summaryrefslogtreecommitdiff
path: root/mysql-test/main
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2022-10-04 16:16:06 +0300
committerSergei Petrunia <sergey@mariadb.com>2023-02-03 00:00:35 +0300
commit727491b72adcf3c10b252a61579f70c7ec2246be (patch)
treeb5ac3878d973ac0a01bd86d0c8a4d7d7723ecc03 /mysql-test/main
parenteb68023c8e3f014495cd694e1b8d5dafc1e37a8e (diff)
downloadmariadb-git-727491b72adcf3c10b252a61579f70c7ec2246be.tar.gz
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)
Diffstat (limited to 'mysql-test/main')
-rw-r--r--mysql-test/main/analyze_format_json.result13
-rw-r--r--mysql-test/main/analyze_format_json.test1
-rw-r--r--mysql-test/main/analyze_stmt_privileges2.result78
-rw-r--r--mysql-test/main/compress.result19
-rw-r--r--mysql-test/main/costs.result42
-rw-r--r--mysql-test/main/cte_nonrecursive.result14
-rw-r--r--mysql-test/main/cte_recursive.result47
-rw-r--r--mysql-test/main/ctype_ucs.result4
-rw-r--r--mysql-test/main/delete.result8
-rw-r--r--mysql-test/main/delete.test7
-rw-r--r--mysql-test/main/delete_innodb.result2
-rw-r--r--mysql-test/main/derived.result24
-rw-r--r--mysql-test/main/derived.test2
-rw-r--r--mysql-test/main/derived_cond_pushdown.result228
-rw-r--r--mysql-test/main/derived_cond_pushdown.test7
-rw-r--r--mysql-test/main/derived_opt.result2
-rw-r--r--mysql-test/main/derived_split_innodb.result24
-rw-r--r--mysql-test/main/derived_view.result22
-rw-r--r--mysql-test/main/desc_index_range.result2
-rw-r--r--mysql-test/main/distinct.result12
-rw-r--r--mysql-test/main/explain.result16
-rw-r--r--mysql-test/main/explain_innodb.result2
-rw-r--r--mysql-test/main/explain_json.result80
-rw-r--r--mysql-test/main/explain_json.test7
-rw-r--r--mysql-test/main/explain_json_innodb.result3
-rw-r--r--mysql-test/main/fetch_first.result9
-rw-r--r--mysql-test/main/fetch_first.test7
-rw-r--r--mysql-test/main/fulltext.result7
-rw-r--r--mysql-test/main/fulltext.test2
-rw-r--r--mysql-test/main/fulltext_order_by.test1
-rw-r--r--mysql-test/main/func_group.result8
-rw-r--r--mysql-test/main/func_group_innodb.result6
-rw-r--r--mysql-test/main/func_group_innodb.test2
-rw-r--r--mysql-test/main/func_in.result16
-rw-r--r--mysql-test/main/greedy_optimizer.result246
-rw-r--r--mysql-test/main/greedy_optimizer.test2
-rw-r--r--mysql-test/main/group_by.result8
-rw-r--r--mysql-test/main/group_min_max.result24
-rw-r--r--mysql-test/main/group_min_max.test1
-rw-r--r--mysql-test/main/group_min_max_innodb.result22
-rw-r--r--mysql-test/main/ignored_index.result14
-rw-r--r--mysql-test/main/ignored_index.test8
-rw-r--r--mysql-test/main/index_intersect.result4
-rw-r--r--mysql-test/main/index_intersect_innodb.result14
-rw-r--r--mysql-test/main/index_merge_innodb.result8
-rw-r--r--mysql-test/main/index_merge_myisam.result14
-rw-r--r--mysql-test/main/information_schema-big.result2
-rw-r--r--mysql-test/main/information_schema.result3
-rw-r--r--mysql-test/main/innodb_ext_key,off.rdiff39
-rw-r--r--mysql-test/main/innodb_ext_key.result29
-rw-r--r--mysql-test/main/innodb_ext_key.test16
-rw-r--r--mysql-test/main/innodb_icp.result22
-rw-r--r--mysql-test/main/innodb_mysql_lock2.test1
-rw-r--r--mysql-test/main/invisible_field_debug.result6
-rw-r--r--mysql-test/main/join.result40
-rw-r--r--mysql-test/main/join.test8
-rw-r--r--mysql-test/main/join_cache.result62
-rw-r--r--mysql-test/main/join_nested.result6
-rw-r--r--mysql-test/main/join_nested_jcl6.result28
-rw-r--r--mysql-test/main/join_outer.result10
-rw-r--r--mysql-test/main/join_outer.test2
-rw-r--r--mysql-test/main/join_outer_innodb.result30
-rw-r--r--mysql-test/main/join_outer_jcl6.result14
-rw-r--r--mysql-test/main/key.result6
-rw-r--r--mysql-test/main/key_cache.result20
-rw-r--r--mysql-test/main/key_cache.test12
-rw-r--r--mysql-test/main/limit_rows_examined.result54
-rw-r--r--mysql-test/main/limit_rows_examined.test6
-rw-r--r--mysql-test/main/mrr_derived_crash_4610.result2
-rw-r--r--mysql-test/main/myisam.result3
-rw-r--r--mysql-test/main/myisam.test1
-rw-r--r--mysql-test/main/myisam_explain_non_select_all.result71
-rw-r--r--mysql-test/main/myisam_icp.result32
-rw-r--r--mysql-test/main/myisam_mrr.result5
-rw-r--r--mysql-test/main/myisam_mrr.test5
-rw-r--r--mysql-test/main/mysqld--help.result6
-rw-r--r--mysql-test/main/named_pipe.result19
-rw-r--r--mysql-test/main/negation_elimination.result6
-rw-r--r--mysql-test/main/opt_trace.result3791
-rw-r--r--mysql-test/main/opt_trace.test65
-rw-r--r--mysql-test/main/opt_trace_index_merge.result164
-rw-r--r--mysql-test/main/opt_trace_index_merge_innodb.result35
-rw-r--r--mysql-test/main/opt_trace_security.result24
-rw-r--r--mysql-test/main/opt_trace_selectivity.result39
-rw-r--r--mysql-test/main/opt_tvc.result6
-rw-r--r--mysql-test/main/optimizer_costs.result347
-rw-r--r--mysql-test/main/optimizer_costs.test187
-rw-r--r--mysql-test/main/optimizer_costs2-master.opt1
-rw-r--r--mysql-test/main/optimizer_costs2.result8
-rw-r--r--mysql-test/main/optimizer_costs2.test6
-rw-r--r--mysql-test/main/order_by.result186
-rw-r--r--mysql-test/main/order_by.test17
-rw-r--r--mysql-test/main/order_by_innodb.result2
-rw-r--r--mysql-test/main/partition.result4
-rw-r--r--mysql-test/main/partition_explicit_prune.result4
-rw-r--r--mysql-test/main/partition_mrr_aria.result4
-rw-r--r--mysql-test/main/partition_mrr_innodb.result4
-rw-r--r--mysql-test/main/partition_mrr_myisam.result6
-rw-r--r--mysql-test/main/partition_pruning.result40
-rw-r--r--mysql-test/main/partition_range.result69
-rw-r--r--mysql-test/main/partition_range.test31
-rw-r--r--mysql-test/main/percona_nonflushing_analyze_debug.result2
-rw-r--r--mysql-test/main/pool_of_threads.result19
-rw-r--r--mysql-test/main/range.result159
-rw-r--r--mysql-test/main/range.test22
-rw-r--r--mysql-test/main/range_innodb.result6
-rw-r--r--mysql-test/main/range_interrupted-13751.result14
-rw-r--r--mysql-test/main/range_interrupted-13751.test14
-rw-r--r--mysql-test/main/range_mrr_icp.result87
-rw-r--r--mysql-test/main/range_notembedded.result8
-rw-r--r--mysql-test/main/range_vs_index_merge.result59
-rw-r--r--mysql-test/main/range_vs_index_merge.test14
-rw-r--r--mysql-test/main/range_vs_index_merge_innodb.result61
-rw-r--r--mysql-test/main/rowid_filter.result471
-rw-r--r--mysql-test/main/rowid_filter.test14
-rw-r--r--mysql-test/main/rowid_filter_innodb.result618
-rw-r--r--mysql-test/main/rowid_filter_innodb.test8
-rw-r--r--mysql-test/main/rowid_filter_innodb_debug.result19
-rw-r--r--mysql-test/main/rowid_filter_myisam_debug.result19
-rw-r--r--mysql-test/main/select.result72
-rw-r--r--mysql-test/main/select.test36
-rw-r--r--mysql-test/main/select_jcl6.result80
-rw-r--r--mysql-test/main/select_pkeycache.result72
-rw-r--r--mysql-test/main/select_safe.result4
-rw-r--r--mysql-test/main/selectivity.result62
-rw-r--r--mysql-test/main/selectivity.test16
-rw-r--r--mysql-test/main/selectivity_innodb.result74
-rw-r--r--mysql-test/main/selectivity_no_engine.result4
-rw-r--r--mysql-test/main/show_explain.result2
-rw-r--r--mysql-test/main/sp.result2
-rw-r--r--mysql-test/main/ssl.result19
-rw-r--r--mysql-test/main/ssl_compress.result19
-rw-r--r--mysql-test/main/stat_tables.result51
-rw-r--r--mysql-test/main/stat_tables.test2
-rw-r--r--mysql-test/main/stat_tables_innodb.result59
-rw-r--r--mysql-test/main/statistics_json.result2
-rw-r--r--mysql-test/main/status.result18
-rw-r--r--mysql-test/main/subselect.result118
-rw-r--r--mysql-test/main/subselect.test49
-rw-r--r--mysql-test/main/subselect2.result10
-rw-r--r--mysql-test/main/subselect2.test4
-rw-r--r--mysql-test/main/subselect3.result12
-rw-r--r--mysql-test/main/subselect3_jcl6.result10
-rw-r--r--mysql-test/main/subselect4.result18
-rw-r--r--mysql-test/main/subselect_exists2in.result24
-rw-r--r--mysql-test/main/subselect_exists2in.test4
-rw-r--r--mysql-test/main/subselect_exists2in_costmat.result4
-rw-r--r--mysql-test/main/subselect_innodb.result4
-rw-r--r--mysql-test/main/subselect_mat.result85
-rw-r--r--mysql-test/main/subselect_mat_cost.result49
-rw-r--r--mysql-test/main/subselect_mat_cost.test31
-rw-r--r--mysql-test/main/subselect_mat_cost_bugs.result26
-rw-r--r--mysql-test/main/subselect_no_exists_to_in.result111
-rw-r--r--mysql-test/main/subselect_no_mat.result119
-rw-r--r--mysql-test/main/subselect_no_opts.result89
-rw-r--r--mysql-test/main/subselect_no_scache.result118
-rw-r--r--mysql-test/main/subselect_no_semijoin.result117
-rw-r--r--mysql-test/main/subselect_partial_match.result10
-rw-r--r--mysql-test/main/subselect_partial_match.test6
-rw-r--r--mysql-test/main/subselect_sj.result71
-rw-r--r--mysql-test/main/subselect_sj.test4
-rw-r--r--mysql-test/main/subselect_sj2.result49
-rw-r--r--mysql-test/main/subselect_sj2.test15
-rw-r--r--mysql-test/main/subselect_sj2_jcl6.result78
-rw-r--r--mysql-test/main/subselect_sj2_jcl6.test3
-rw-r--r--mysql-test/main/subselect_sj2_mat.result98
-rw-r--r--mysql-test/main/subselect_sj_jcl6.result125
-rw-r--r--mysql-test/main/subselect_sj_jcl6.test19
-rw-r--r--mysql-test/main/subselect_sj_mat.result184
-rw-r--r--mysql-test/main/subselect_sj_mat.test23
-rw-r--r--mysql-test/main/subselect_sj_nonmerged.result4
-rw-r--r--mysql-test/main/type_blob.result10
-rw-r--r--mysql-test/main/type_datetime.result2
-rw-r--r--mysql-test/main/view.result38
-rw-r--r--mysql-test/main/view.test6
175 files changed, 6165 insertions, 4485 deletions
diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result
index 7fd783e4355..99ac42d34bd 100644
--- a/mysql-test/main/analyze_format_json.result
+++ b/mysql-test/main/analyze_format_json.result
@@ -771,12 +771,12 @@ ANALYZE
"r_other_time_ms": "REPLACED",
"filtered": 100,
"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_size": "65",
"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_unpack_time_ms": "REPLACED"
}
@@ -786,21 +786,20 @@ ANALYZE
{
"query_block": {
"select_id": 2,
- "r_loops": 2,
+ "r_loops": 1,
"r_total_time_ms": "REPLACED",
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "ALL",
- "r_loops": 2,
+ "r_loops": 1,
"rows": 2,
"r_rows": 2,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
- "r_filtered": 0,
- "attached_condition": "4 = t1.a"
+ "r_filtered": 100
}
}
]
@@ -809,6 +808,8 @@ ANALYZE
]
}
}
+SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
+a b
drop table t1,t2;
#
# MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON
diff --git a/mysql-test/main/analyze_format_json.test b/mysql-test/main/analyze_format_json.test
index 3f3324e9eec..8c0948daac9 100644
--- a/mysql-test/main/analyze_format_json.test
+++ b/mysql-test/main/analyze_format_json.test
@@ -190,6 +190,7 @@ INSERT INTO t2 VALUES (3),(4);
--source include/analyze-format.inc
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;
diff --git a/mysql-test/main/analyze_stmt_privileges2.result b/mysql-test/main/analyze_stmt_privileges2.result
index 4a499e0c7ef..0dec4722802 100644
--- a/mysql-test/main/analyze_stmt_privileges2.result
+++ b/mysql-test/main/analyze_stmt_privileges2.result
@@ -377,13 +377,11 @@ a b
EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.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)
#------------------------------------------------------------------------
# I/R/U/D/S on the inner view
# Expectation: Can run everything
@@ -492,13 +490,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#------------------------------------------------------------------------
# I/R/U/D/S on the outer view
# Expectation: Can run everything
@@ -599,13 +595,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 12 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#========================================================================
# Test: Grant INSERT on the table
@@ -1592,13 +1586,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#------------------------------------------------------------------------
# I/R/U/D/S on the outer view
# 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 );
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 <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#========================================================================
# 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 );
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 <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#------------------------------------------------------------------------
# I/R/U/D/S on the outer view
# Expectation: Can run everything
@@ -2049,13 +2037,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#########################################################################
# Inner view permission tests
@@ -2698,13 +2684,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 14 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#------------------------------------------------------------------------
# I/R/U/D/S on the outer view
# Expectation: Can run everything
@@ -2805,13 +2789,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 18 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#========================================================================
# Test: Grant INSERT on the inner view
@@ -3988,13 +3970,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 35 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#------------------------------------------------------------------------
# I/R/U/D/S on the outer view
# Expectation: Can run everything
@@ -4095,13 +4075,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#########################################################################
# Outer view permission tests
@@ -4615,13 +4593,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
#========================================================================
# Test: Grant INSERT on the outer view
@@ -5222,13 +5198,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 44 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
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
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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)
disconnect con1;
connection default;
DROP USER 'privtest'@localhost;
diff --git a/mysql-test/main/compress.result b/mysql-test/main/compress.result
index 24979346149..f5c85d3eb6f 100644
--- a/mysql-test/main/compress.result
+++ b/mysql-test/main/compress.result
@@ -6,6 +6,7 @@ select * from information_schema.session_status where variable_name= 'COMPRESSIO
VARIABLE_NAME VARIABLE_VALUE
COMPRESSION ON
drop table if exists t1,t2,t3,t4;
+set @@default_storage_engine="aria";
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' 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
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
+#
+# Some test with ORDER BY and limit
+#
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
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 '',
PRIMARY KEY (companynr),
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;
companynr companyname
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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
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;
id select_type table type possible_keys key key_len ref rows Extra
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
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
-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
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
-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
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
-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
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
@@ -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
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
-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
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
-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
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
diff --git a/mysql-test/main/costs.result b/mysql-test/main/costs.result
index 879d586790b..8349bcf886f 100644
--- a/mysql-test/main/costs.result
+++ b/mysql-test/main/costs.result
@@ -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;
id select_type table type possible_keys key key_len ref rows Extra
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;
id select_type table type possible_keys key key_len ref rows Extra
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
#
@@ -21,71 +21,71 @@ id select_type table type possible_keys key key_len ref rows Extra
Last_query_cost 0.000000
explain select count(*) from t1 where a > 0;
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
-Last_query_cost 3.202929
+1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index
+Last_query_cost 0.002795
explain select count(*) from t1 where a > 1;
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
-Last_query_cost 3.202929
+1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index
+Last_query_cost 0.002795
explain select count(*) from t1 where a > 2;
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
-Last_query_cost 2.997685
+Last_query_cost 0.002665
#
# Shorter indexes are prefered over longer indexs
#
explain select sum(a+b) from t1;
id select_type table type possible_keys key key_len ref rows Extra
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;
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
-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;
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
-Last_query_cost 0.970781
+1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index
+Last_query_cost 0.001494
# Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd'
explain select count(*) from t1 where b > 6;
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
-Last_query_cost 1.646831
+Last_query_cost 0.001885
explain select count(*) from t1 where d > 6;
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
-Last_query_cost 1.646343
+Last_query_cost 0.001885
#
# Check covering index usage
#
explain select a,b,c from t1 where a=b;
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
-Last_query_cost 3.205859
+Last_query_cost 0.007441
#
# Prefer ref keys over ranges
#
explain select count(*) from t1 where b=2;
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
-Last_query_cost 0.950732
+Last_query_cost 0.001059
explain select count(*) from t1 where b=2 and c=2;
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
-Last_query_cost 0.950781
+1 SIMPLE t1 ref ba,bda,cba,cb cba 10 const,const 2 Using index
+Last_query_cost 0.001059
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
-1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index
-Last_query_cost 0.970781
+1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index
+Last_query_cost 0.001494
#
# Prefer eq keys over ref keys
#
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
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;
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
-Last_query_cost 2.520537
+Last_query_cost 0.003126
drop table t1;
diff --git a/mysql-test/main/cte_nonrecursive.result b/mysql-test/main/cte_nonrecursive.result
index 58418cc7d9d..cadaa5f819a 100644
--- a/mysql-test/main/cte_nonrecursive.result
+++ b/mysql-test/main/cte_nonrecursive.result
@@ -150,16 +150,14 @@ explain
with t as (select a from t1 where a<5)
select * from t2 where c in (select a from t);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
-3 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
explain
select * from t2
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
-1 PRIMARY t2 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
# materialized t is used in a subquery
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);
@@ -2300,14 +2298,14 @@ WHERE col1 IN ( SELECT col FROM t );
SELECT * FROM tt;
col2
2018-10-01
-2018-10-01
2017-10-01
+2018-10-01
SELECT t4.col1
FROM tt, t4
WHERE t4.col2 = tt.col2 AND t4.col1 IN ( SELECT col FROM t );
col1
-8
4
+8
DROP TABLE t,tt;
CALL SP1();
col1
diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result
index a7b73b80845..f6a71b2f53c 100644
--- a/mysql-test/main/cte_recursive.result
+++ b/mysql-test/main/cte_recursive.result
@@ -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.w_id 2 100.00
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 <derived2> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
-5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00
-5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
+4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where
+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 Using where
+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
2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
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 <derived3> ref key0 key0 23 test.t1.a1 1 FirstMatch(t1)
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 ref b1 b1 23 cte.a2 2
+4 RECURSIVE UNION tt2 ALL b1 NULL NULL NULL 14 Using where
+4 RECURSIVE UNION <derived3> ref key0 key0 23 test.tt2.b1 1
NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL
analyze format=json select fv
from (select t1.a1, f1(t1.a2) fv from t1) dt
@@ -3946,30 +3946,31 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "<derived3>",
+ "table_name": "tt2",
"access_type": "ALL",
+ "possible_keys": ["b1"],
"r_loops": 1,
- "rows": 2,
- "r_rows": 1,
+ "rows": 14,
+ "r_rows": 14,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100,
- "attached_condition": "cte.a2 is not null"
+ "attached_condition": "tt2.b1 is not null"
}
},
{
"table": {
- "table_name": "tt2",
+ "table_name": "<derived3>",
"access_type": "ref",
- "possible_keys": ["b1"],
- "key": "b1",
+ "possible_keys": ["key0"],
+ "key": "key0",
"key_length": "23",
- "used_key_parts": ["b1"],
- "ref": ["cte.a2"],
- "r_loops": 1,
- "rows": 2,
- "r_rows": 1,
+ "used_key_parts": ["a2"],
+ "ref": ["test.tt2.b1"],
+ "r_loops": 14,
+ "rows": 1,
+ "r_rows": 0.071428571,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"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);
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 <derived5> ref key0 key0 5 const 0 0.00
-1 PRIMARY <derived4> 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 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 <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 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)
-2 RECURSIVE UNION h ALL NULL NULL NULL NULL 12
-2 RECURSIVE UNION <derived4> ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-2 RECURSIVE UNION 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 Using where
+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 (flat, BNL join)
NULL UNION RESULT <union3,2> ALL NULL NULL NULL NULL NULL
prepare stmt from "with recursive
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,
diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result
index ce8e1c2e83b..e53b00806f1 100644
--- a/mysql-test/main/ctype_ucs.result
+++ b/mysql-test/main/ctype_ucs.result
@@ -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
EXPLAIN SELECT * FROM t1 WHERE a LIKE 'c%';
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%';
a
ca
@@ -1585,7 +1585,7 @@ ch
ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ucs2 COLLATE ucs2_croatian_ci;
EXPLAIN SELECT * FROM t1 WHERE a LIKE 'd%';
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,'%'));
hex(concat('d',_ucs2 0x017E,'%'))
0064017E0025
diff --git a/mysql-test/main/delete.result b/mysql-test/main/delete.result
index 77a1f8c9813..830f60aa3c7 100644
--- a/mysql-test/main/delete.result
+++ b/mysql-test/main/delete.result
@@ -92,6 +92,9 @@ select * from t1;
a b
1 apple
drop table t1;
+#
+# IGNORE option
+#
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 t2 (a int NOT NULL, b int, primary key (a));
@@ -125,6 +128,11 @@ a b
33 10
0 11
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);
Warnings:
Warning 1242 Subquery returns more than 1 row
diff --git a/mysql-test/main/delete.test b/mysql-test/main/delete.test
index c82420640c2..b95919ee4a4 100644
--- a/mysql-test/main/delete.test
+++ b/mysql-test/main/delete.test
@@ -106,9 +106,9 @@ delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
select * from t1;
drop table t1;
-#
-# IGNORE option
-#
+--echo #
+--echo # IGNORE option
+--echo #
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 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);
select * from t11;
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);
select * from t11;
select * from t12;
diff --git a/mysql-test/main/delete_innodb.result b/mysql-test/main/delete_innodb.result
index b9f4c8bdaf5..ae9b415152f 100644
--- a/mysql-test/main/delete_innodb.result
+++ b/mysql-test/main/delete_innodb.result
@@ -17,7 +17,7 @@ a
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
-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
DELETE b FROM t1 AS a JOIN t1 AS b;
SELECT * FROM t1;
diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result
index b3acbdfce16..422b2b07230 100644
--- a/mysql-test/main/derived.result
+++ b/mysql-test/main/derived.result
@@ -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;
id select_type table type possible_keys key key_len ref rows Extra
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
3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where
drop table t1;
@@ -1346,7 +1346,7 @@ DROP TABLE t1;
# Test of "Derived tables and union can now create distinct keys"
#
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);
insert into duplicates_tbl select seq/100 from seq_1_to_10000;
explain
@@ -1360,7 +1360,7 @@ where T.a=5
) as 'A'
from t1;
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
3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000
select
@@ -1375,6 +1375,14 @@ from t1;
A
1
1
+1
+1
+1
+1
+1
+1
+1
+1
explain
select
t1.a = all ( SELECT COUNT(*)
@@ -1386,7 +1394,7 @@ where T.a=5
) as 'A'
from t1;
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
3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000
select
@@ -1401,6 +1409,14 @@ from t1;
A
1
1
+1
+1
+1
+1
+1
+1
+1
+1
drop table t1, duplicates_tbl;
#
# End of 11.0 tests
diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test
index 8c76fe50fe7..3bb52e603f9 100644
--- a/mysql-test/main/derived.test
+++ b/mysql-test/main/derived.test
@@ -1156,7 +1156,7 @@ DROP TABLE t1;
--echo #
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);
insert into duplicates_tbl select seq/100 from seq_1_to_10000;
diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index ce0338bee1f..bf3b8591f0f 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -8174,7 +8174,7 @@ EXPLAIN
"table_name": "t2",
"access_type": "ALL",
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"attached_condition": "t2.b = 2",
"first_match": "t1"
}
@@ -8272,7 +8272,7 @@ EXPLAIN
"table_name": "t2",
"access_type": "ALL",
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"attached_condition": "t2.b = 2",
"first_match": "t1"
}
@@ -8799,8 +8799,8 @@ EXPLAIN
"table": {
"table_name": "<subquery2>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -8869,8 +8869,8 @@ EXPLAIN
"table": {
"table_name": "<subquery2>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -8969,8 +8969,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9036,8 +9036,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9098,8 +9098,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9160,8 +9160,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9224,8 +9224,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9286,8 +9286,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -9348,8 +9348,8 @@ EXPLAIN
"table": {
"table_name": "<subquery3>",
"access_type": "system",
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"materialized": {
"unique": 1,
"query_block": {
@@ -17526,7 +17526,7 @@ on t1.a=t.a
where t1.b < 3;
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 <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
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
@@ -17564,7 +17564,7 @@ EXPLAIN
"used_key_parts": ["a"],
"ref": ["test.t1.a"],
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"materialized": {
"lateral": 1,
"query_block": {
@@ -17647,7 +17647,7 @@ on t1.a=t.a
where t1.b <= 5;
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 <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
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
@@ -17681,7 +17681,7 @@ EXPLAIN
"used_key_parts": ["a"],
"ref": ["test.t1.a"],
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"materialized": {
"lateral": 1,
"query_block": {
@@ -17762,7 +17762,7 @@ from t1 left join
on t1.a=t.a;
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 <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
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
@@ -17794,7 +17794,7 @@ EXPLAIN
"used_key_parts": ["a"],
"ref": ["test.t1.a"],
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"attached_condition": "trigcond(trigcond(t1.a is not null))",
"materialized": {
"lateral": 1,
@@ -17953,10 +17953,10 @@ on t3.a=t.a and t3.c=t.c
where t3.b <= 15;
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 <derived2> ref key0 key0 133 test.t3.a,test.t3.c 4 100.00
-2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort
+1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 2 50.00
+2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00
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
from t3 join
(select a, c, max(b) max, min(b) min from t4 group by a,c) t
@@ -17986,27 +17986,28 @@ EXPLAIN
"key_length": "133",
"used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"],
- "rows": 4,
- "filtered": 100,
+ "rows": 2,
+ "filtered": 50,
"materialized": {
+ "lateral": 1,
"query_block": {
"select_id": 2,
- "filesort": {
- "sort_key": "t4.a, t4.c",
- "temporary_table": {
- "nested_loop": [
- {
- "table": {
- "table_name": "t4",
- "access_type": "ALL",
- "possible_keys": ["idx"],
- "rows": 40,
- "filtered": 100
- }
- }
- ]
+ "outer_ref_condition": "t3.a is not null and t3.c is not null",
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "t4",
+ "access_type": "ref",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "133",
+ "used_key_parts": ["a", "c"],
+ "ref": ["test.t3.a", "test.t3.c"],
+ "rows": 1,
+ "filtered": 100
+ }
}
- }
+ ]
}
}
}
@@ -18126,10 +18127,10 @@ on t3.a=t.a and t3.c=t.c
where t3.b <= 15;
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 <derived2> ref key0 key0 133 test.t3.a,test.t3.c 4 100.00
-2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort
+1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 2 50.00
+2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00
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
from t3 join
(select a, c, max(b) max, min(b) min from t4 group by c,a) t
@@ -18159,27 +18160,28 @@ EXPLAIN
"key_length": "133",
"used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"],
- "rows": 4,
- "filtered": 100,
+ "rows": 2,
+ "filtered": 50,
"materialized": {
+ "lateral": 1,
"query_block": {
"select_id": 2,
- "filesort": {
- "sort_key": "t4.c, t4.a",
- "temporary_table": {
- "nested_loop": [
- {
- "table": {
- "table_name": "t4",
- "access_type": "ALL",
- "possible_keys": ["idx"],
- "rows": 40,
- "filtered": 100
- }
- }
- ]
+ "outer_ref_condition": "t3.a is not null and t3.c is not null",
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "t4",
+ "access_type": "ref",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "133",
+ "used_key_parts": ["a", "c"],
+ "ref": ["test.t3.a", "test.t3.c"],
+ "rows": 1,
+ "filtered": 100
+ }
}
- }
+ ]
}
}
}
@@ -19022,7 +19024,7 @@ a c
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
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 <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00
4 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 100.00
@@ -19059,7 +19061,7 @@ EXPLAIN
"used_key_parts": ["c"],
"ref": ["test.t4.c"],
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"first_match": "t4",
"materialized": {
"lateral": 1,
@@ -19413,7 +19415,7 @@ GROUP BY t1.b,t2.c) dt
WHERE t3.d = dt.b;
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 <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 t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings:
@@ -19503,7 +19505,7 @@ id a
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
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 t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
Warnings:
@@ -19541,7 +19543,7 @@ on (t1.id = t2.ro_id AND t2.flag = 1)
group by t1.id) dt);
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 <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 t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
Warnings:
@@ -19724,6 +19726,7 @@ insert into t1 values
(17,1),(17,3010),(17,3013),(17,3053),(21,2446),(21,2467),(21,2);
create table t2 (a int) engine=myisam;
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;
insert into t3 values (1),(2);
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 <subquery3> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY <derived2> ref key0 key0 5 test.t3.id 2
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 6
-2 DERIVED cp2 index NULL a 5 NULL 7 Using index
+3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1007
+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
where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2);
EXPLAIN
@@ -19798,7 +19801,7 @@ EXPLAIN
"table": {
"table_name": "t2",
"access_type": "ALL",
- "rows": 6,
+ "rows": 1007,
"filtered": 100
}
}
@@ -19825,13 +19828,13 @@ EXPLAIN
{
"table": {
"table_name": "cp2",
- "access_type": "index",
+ "access_type": "range",
"key": "a",
"key_length": "5",
"used_key_parts": ["a"],
"rows": 7,
"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 <subquery3> eq_ref distinct_key distinct_key 4 func 1
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
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);
@@ -19906,7 +19909,7 @@ EXPLAIN
"table": {
"table_name": "t2",
"access_type": "ALL",
- "rows": 6,
+ "rows": 1007,
"filtered": 100
}
}
@@ -19968,7 +19971,7 @@ id a a id
deallocate prepare stmt;
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 (
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;
INSERT INTO t2(deleted, t1_id, email, reporting_person)
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 (
id int PRIMARY KEY,
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
WHERE t1.id BETWEEN 200 AND 100000;
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 <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
FROM t1
JOIN t3
@@ -20078,11 +20082,11 @@ EXPLAIN
{
"table": {
"table_name": "t3",
- "access_type": "index",
+ "access_type": "range",
"possible_keys": ["t1_id"],
"key": "t1_id",
- "key_length": "15",
- "used_key_parts": ["t1_id", "YEAR", "quarter"],
+ "key_length": "5",
+ "used_key_parts": ["t1_id"],
"rows": 47,
"filtered": 100,
"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"],
"ref": ["test.t3.t1_id"],
"rows": 2,
- "filtered": 100,
+ "filtered": 50,
"materialized": {
"lateral": 1,
"query_block": {
@@ -20128,8 +20132,8 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["t1_id"],
"ref": ["test.t1.id"],
- "rows": 3,
- "filtered": 59.09090805,
+ "rows": 1,
+ "filtered": 34.55045319,
"index_condition": "t2.t1_id between 200 and 100000 and t2.t1_id = t3.t1_id",
"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
WHERE t1.id BETWEEN 200 AND 100000;
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';
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
WHERE charges.to_ledger_id = 2;
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
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
@@ -20303,15 +20319,18 @@ EXPLAIN
{
"table": {
"table_name": "charges",
- "access_type": "ALL",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"fk_charge_from_ledger",
"fk_charge_to_ledger"
],
- "rows": 20,
- "filtered": 40,
- "attached_condition": "charges.to_ledger_id = 2"
+ "key": "fk_charge_to_ledger",
+ "key_length": "8",
+ "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
WHERE charges.to_ledger_id = 2;
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
-2 DERIVED transactions ALL PRIMARY 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 transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort
+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
(101, 4, 2, 100), (102, 7, 2, 200);
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
WHERE charges.to_ledger_id = 2;
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
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
@@ -20497,11 +20516,14 @@ EXPLAIN
{
"table": {
"table_name": "charges",
- "access_type": "ALL",
+ "access_type": "ref",
"possible_keys": ["fk_charge_to_ledger"],
- "rows": 20,
- "filtered": 50,
- "attached_condition": "charges.to_ledger_id = 2"
+ "key": "fk_charge_to_ledger",
+ "key_length": "8",
+ "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
WHERE charges.to_ledger_id = 2;
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
-2 DERIVED transactions ALL PRIMARY 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 transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort
+2 DERIVED transactions eq_ref PRIMARY PRIMARY 8 test.transaction_items.transaction_id 1
set optimizer_switch='split_materialized=default';
DROP TABLE transaction_items;
DROP TABLE transactions;
diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test
index 83e784c3450..55ccd9b4839 100644
--- a/mysql-test/main/derived_cond_pushdown.test
+++ b/mysql-test/main/derived_cond_pushdown.test
@@ -3602,6 +3602,7 @@ insert into t1 values
create table t2 (a int) engine=myisam;
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;
insert into t3 values (1),(2);
@@ -3630,7 +3631,7 @@ deallocate prepare stmt;
drop table t1,t2,t3;
--echo #
---echo # MDEV-MDEV-27132: Splittable derived with equality in WHERE
+--echo # MDEV-27132: Splittable derived with equality in WHERE
--echo #
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)
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 (
id int PRIMARY KEY,
deleted int,
@@ -3724,6 +3728,7 @@ eval EXPLAIN FORMAT=JSON $q;
set optimizer_switch='split_materialized=off';
eval $q;
+eval EXPLAIN $q;
set optimizer_switch='split_materialized=default';
diff --git a/mysql-test/main/derived_opt.result b/mysql-test/main/derived_opt.result
index 051360ffe8c..7d02990fb5d 100644
--- a/mysql-test/main/derived_opt.result
+++ b/mysql-test/main/derived_opt.result
@@ -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;
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 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
drop table t1;
create table t1 (a int);
diff --git a/mysql-test/main/derived_split_innodb.result b/mysql-test/main/derived_split_innodb.result
index be3de7dbc02..c326a895a38 100644
--- a/mysql-test/main/derived_split_innodb.result
+++ b/mysql-test/main/derived_split_innodb.result
@@ -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
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
-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
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
n1
@@ -128,8 +128,8 @@ left join
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
on t1.f1=t.f1;
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 <derived2> const key1 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 0 Impossible ON condition
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
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
@@ -138,8 +138,8 @@ left join
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
on t1.f1=t.f1;
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 <derived3> const key1 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 0 Impossible ON condition
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
3 DERIVED t2 index NULL PRIMARY 4 NULL 3
drop view v1;
@@ -157,26 +157,26 @@ set statement optimizer_switch='split_materialized=off' for EXPLAIN
SELECT *
FROM
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
t1.a = dt.a;
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 <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 t2 ref c c 5 test.t1.b 1 Using index
+3 DERIVED t1_inner index NULL a_2 10 NULL 6 Using where; 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
SELECT *
FROM
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
t1.a = dt.a;
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 <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 t2 ref c c 5 test.t1.b 1 Using index
+3 DERIVED t1_inner index a,a_2 a_2 10 NULL 6 Using where; Using index
+3 DERIVED t2_inner ref c c 5 test.t1_inner.b 1 Using index
DROP TABLE t1, t2;
#
# 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 t1 ref idx idx 4 test.t2.id 1
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
from t1,
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
diff --git a/mysql-test/main/derived_view.result b/mysql-test/main/derived_view.result
index a64894441c8..dd74d2953b0 100644
--- a/mysql-test/main/derived_view.result
+++ b/mysql-test/main/derived_view.result
@@ -1216,11 +1216,11 @@ SELECT * FROM t3
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
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; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+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
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
WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b);
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
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
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using filesort
-1 PRIMARY t4 ref f2 f2 4 t.f1 1 Using index
-1 PRIMARY t3 ref f2 f2 4 t.f1 2 Using index
+1 PRIMARY t4 index f2 f2 9 NULL 2 Using where; Using index; Using temporary; Using filesort
+1 PRIMARY t3 ref f2 f2 4 test.t4.f2 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 t1 ref f2 f2 4 const 2 Using where
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
1 PRIMARY t2 system NULL NULL NULL NULL 1
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
SELECT * FROM t3
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);
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 <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
SELECT COUNT(*) > 0
FROM INFORMATION_SCHEMA.COLUMNS
@@ -2463,8 +2463,6 @@ SELECT * FROM t1;
a
1
1
-1
-1
drop table t1,t2;
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
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
-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:
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;
@@ -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
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
-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:
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;
diff --git a/mysql-test/main/desc_index_range.result b/mysql-test/main/desc_index_range.result
index a540efe33d6..1dc17702a9f 100644
--- a/mysql-test/main/desc_index_range.result
+++ b/mysql-test/main/desc_index_range.result
@@ -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;
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
-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'))
from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.potential_group_range_indexes'))
diff --git a/mysql-test/main/distinct.result b/mysql-test/main/distinct.result
index 3064e062781..d789066ac3b 100644
--- a/mysql-test/main/distinct.result
+++ b/mysql-test/main/distinct.result
@@ -173,9 +173,9 @@ INSERT INTO t2 values (1),(2),(3);
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;
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 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;
a
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
WHERE t1_1.a = t1_2.a;
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 eq_ref PRIMARY PRIMARY 4 test.t1_1.a 1 Using index; Distinct
+1 SIMPLE t1_2 index PRIMARY PRIMARY 4 NULL 3 Using index; Using temporary
+1 SIMPLE t1_1 eq_ref PRIMARY PRIMARY 4 test.t1_2.a 1
EXPLAIN SELECT a FROM t1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
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);
EXPLAIN SELECT DISTINCT a FROM t2;
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;
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index
diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result
index a5ad9fad4ba..1e546d42d0a 100644
--- a/mysql-test/main/explain.result
+++ b/mysql-test/main/explain.result
@@ -333,9 +333,7 @@ WHERE t1.f1 GROUP BY t1.f1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 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
-Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: 'test'
+2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
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
1 PRIMARY t1 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
-Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: 'test'
+2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 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
-Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: 'test'
+2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
@@ -365,9 +359,7 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 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
-Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: 'test'
+2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5');
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
diff --git a/mysql-test/main/explain_innodb.result b/mysql-test/main/explain_innodb.result
index fe51e45e35d..0bdd5a44985 100644
--- a/mysql-test/main/explain_innodb.result
+++ b/mysql-test/main/explain_innodb.result
@@ -15,6 +15,6 @@ explain
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
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;
drop table t1;
diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result
index d861eff05f1..d2a8f38c33e 100644
--- a/mysql-test/main/explain_json.result
+++ b/mysql-test/main/explain_json.result
@@ -713,12 +713,11 @@ EXPLAIN
create table t2 like t1;
insert into t2 select * from t1;
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
{
"query_block": {
"select_id": 1,
- "const_condition": "1",
"nested_loop": [
{
"table": {
@@ -734,11 +733,12 @@ EXPLAIN
"access_type": "eq_ref",
"possible_keys": ["distinct_key"],
"key": "distinct_key",
- "key_length": "4",
- "used_key_parts": ["a"],
+ "key_length": "8",
+ "used_key_parts": ["seq+0"],
"ref": ["func"],
"rows": 1,
"filtered": 100,
+ "attached_condition": "t1.a = seq_1_to_100.seq + 0",
"materialized": {
"unique": 1,
"query_block": {
@@ -746,10 +746,14 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "t0",
- "access_type": "ALL",
- "rows": 10,
- "filtered": 100
+ "table_name": "seq_1_to_100",
+ "access_type": "index",
+ "key": "PRIMARY",
+ "key_length": "8",
+ "used_key_parts": ["seq"],
+ "rows": 100,
+ "filtered": 100,
+ "using_index": true
}
}
]
@@ -766,7 +770,7 @@ EXPLAIN
"filtered": 100
},
"buffer_type": "flat",
- "buffer_size": "1Kb",
+ "buffer_size": "19Kb",
"join_type": "BNL"
}
}
@@ -847,7 +851,7 @@ EXPLAIN
"table_name": "t1",
"access_type": "ALL",
"rows": 10,
- "filtered": 100
+ "filtered": 10
},
"buffer_type": "flat",
"buffer_size": "206",
@@ -1225,12 +1229,18 @@ analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
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');
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');
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
{
@@ -1241,7 +1251,7 @@ EXPLAIN
"table": {
"table_name": "t1",
"access_type": "range",
- "key": "idx_t1_1",
+ "key": "idx_t1_2",
"key_length": "147",
"used_key_parts": ["a1", "a2", "b"],
"rows": 17,
@@ -1262,13 +1272,36 @@ EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "range",
+ "access_type": "index",
"key": "idx_t1_1",
"key_length": "163",
"used_key_parts": ["a1", "a2", "b", "c"],
- "rows": 65,
- "filtered": 100,
+ "rows": 128,
+ "filtered": 0.198364258,
"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
}
}
@@ -1470,7 +1503,7 @@ insert into t2 values (1),(2);
explain
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
-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
explain format=json
select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
@@ -1485,8 +1518,8 @@ EXPLAIN
"table_name": "t2",
"access_type": "const",
"possible_keys": ["PRIMARY"],
- "rows": 1,
- "filtered": 100,
+ "rows": 0,
+ "filtered": 0,
"impossible_on_condition": true
}
},
@@ -1520,9 +1553,9 @@ ANALYZE
"access_type": "const",
"possible_keys": ["PRIMARY"],
"r_loops": 0,
- "rows": 1,
+ "rows": 0,
"r_rows": null,
- "filtered": 100,
+ "filtered": 0,
"r_filtered": null,
"impossible_on_condition": true
}
@@ -1832,7 +1865,8 @@ ANALYZE
"buffer_size": "400",
"join_type": "BKA",
"mrr_type": "Rowid-ordered scan",
- "r_filtered": 100
+ "r_filtered": 100,
+ "r_unpack_time_ms": "REPLACED"
}
}
]
@@ -2004,7 +2038,7 @@ EXPLAIN
"table_name": "t3",
"access_type": "ALL",
"rows": 2,
- "filtered": 100
+ "filtered": 25
},
"buffer_type": "incremental",
"buffer_size": "109",
diff --git a/mysql-test/main/explain_json.test b/mysql-test/main/explain_json.test
index baf1aa988a2..be077b22f48 100644
--- a/mysql-test/main/explain_json.test
+++ b/mysql-test/main/explain_json.test
@@ -2,6 +2,7 @@
# EXPLAIN FORMAT=JSON tests. These are tests developed for MariaDB.
#
--source include/default_optimizer_switch.inc
+--source include/have_sequence.inc
--disable_warnings
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;
insert into t2 select * from t1;
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 # 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_2 on t1 (a1,a2,b);
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,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,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;
--echo #
diff --git a/mysql-test/main/explain_json_innodb.result b/mysql-test/main/explain_json_innodb.result
index 871c0d6a258..9d2529471ae 100644
--- a/mysql-test/main/explain_json_innodb.result
+++ b/mysql-test/main/explain_json_innodb.result
@@ -54,8 +54,7 @@ EXPLAIN
],
"rows": 1,
"filtered": 100,
- "attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2",
- "using_index": true
+ "attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2"
}
}
]
diff --git a/mysql-test/main/fetch_first.result b/mysql-test/main/fetch_first.result
index c277362739a..f8309f51832 100644
--- a/mysql-test/main/fetch_first.result
+++ b/mysql-test/main/fetch_first.result
@@ -834,6 +834,14 @@ fetch first 2 rows with ties;
first_name last_name
Alice Fowler
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
from t1
where first_name != 'John'
@@ -843,7 +851,6 @@ fetch first 2 rows with ties;
first_name last_name
Alice Fowler
Bob Trasc
-Silvia Ganush
#
# Test CTE support.
#
diff --git a/mysql-test/main/fetch_first.test b/mysql-test/main/fetch_first.test
index 614c91d9ee5..3cec50257fe 100644
--- a/mysql-test/main/fetch_first.test
+++ b/mysql-test/main/fetch_first.test
@@ -621,7 +621,12 @@ where first_name != 'John'
order by first_name
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
from t1
diff --git a/mysql-test/main/fulltext.result b/mysql-test/main/fulltext.result
index 3acde6121ec..3a338fdc847 100644
--- a/mysql-test/main/fulltext.result
+++ b/mysql-test/main/fulltext.result
@@ -594,6 +594,9 @@ CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2));
INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int);
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
EXPLAIN
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
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
-2 MATERIALIZED t2 fulltext b2 b2 0 1 Using where
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 fulltext b2 b2 0 1 Using where
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
# should return 0
SELECT count(*) FROM t1 WHERE
not exists(
diff --git a/mysql-test/main/fulltext.test b/mysql-test/main/fulltext.test
index 8b90c9cd81d..ef690be2314 100644
--- a/mysql-test/main/fulltext.test
+++ b/mysql-test/main/fulltext.test
@@ -547,6 +547,8 @@ INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int);
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
EXPLAIN
SELECT count(*) FROM t1 WHERE
diff --git a/mysql-test/main/fulltext_order_by.test b/mysql-test/main/fulltext_order_by.test
index 4c0333d0afb..9fddf3b2fec 100644
--- a/mysql-test/main/fulltext_order_by.test
+++ b/mysql-test/main/fulltext_order_by.test
@@ -36,7 +36,6 @@ SELECT IF(a=7,'match',IF(a=4,'match', 'no-match')), MATCH (message) AGAINST ('st
# for fulltext searches too
#
alter table t1 add key m (message);
-show create table t1;
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;
diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result
index 5d9b1df58ba..e31d85df358 100644
--- a/mysql-test/main/func_group.result
+++ b/mysql-test/main/func_group.result
@@ -607,7 +607,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain
select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK');
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
select max(a3) from t1 where a2 < 2 and a3 < 'SEA';
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
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
-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)
drop table t1, t2;
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 );
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
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;
MIN(b) MIN(c)
3 2
@@ -1856,7 +1856,7 @@ NULL
EXPLAIN EXTENDED
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
-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)
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
diff --git a/mysql-test/main/func_group_innodb.result b/mysql-test/main/func_group_innodb.result
index f5a823e4638..9f69f424f33 100644
--- a/mysql-test/main/func_group_innodb.result
+++ b/mysql-test/main/func_group_innodb.result
@@ -246,12 +246,12 @@ INSERT INTO t1(a, b, c) VALUES
('', 'a', 1), ('', 'a', 1), ('', 'a', 2), ('', 'a', 2), ('', 'a', 3),
('', 'a', 3), ('', 'a', 4), ('', 'a', 4), ('', 'a', 5), ('', 'a', 5);
ANALYZE TABLE t1;
-SELECT MIN(c) FROM t1 GROUP BY b;
-MIN(c)
-0
EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
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
+SELECT MIN(c) FROM t1 GROUP BY b;
+MIN(c)
+0
DROP TABLE t1;
#
# MDEV-17589: Stack-buffer-overflow with indexed varchar (utf8) field
diff --git a/mysql-test/main/func_group_innodb.test b/mysql-test/main/func_group_innodb.test
index b1f9a28b190..ca6b083848c 100644
--- a/mysql-test/main/func_group_innodb.test
+++ b/mysql-test/main/func_group_innodb.test
@@ -199,8 +199,8 @@ INSERT INTO t1(a, b, c) VALUES
ANALYZE TABLE t1;
-- enable_result_log
-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;
diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result
index 13eb9501599..175e23ec65f 100644
--- a/mysql-test/main/func_in.result
+++ b/mysql-test/main/func_in.result
@@ -521,7 +521,7 @@ 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
-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);
f1
1
@@ -957,7 +957,7 @@ a
# Conversion to equality is impossible due to different values
EXPLAIN SELECT * FROM t1 WHERE a IN (1,1,2);
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);
a
1
@@ -1030,7 +1030,7 @@ a b
# No conversion due to different values
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
-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));
a b
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
EXECUTE stmt USING 2,3,4;
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;
DROP TABLE t1, t2, t3;
# 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
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 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)
# Conversion to equalities
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)
ON t1.a = t2.a WHERE t1.a IN (1,3);
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 t4 ALL NULL NULL NULL NULL 2 Using where
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
EXPLAIN SELECT * FROM v1 WHERE a IN (1,2,3);
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
# Stored procedures
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
CALL p1(2,1);
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 VIEW v1;
DROP PROCEDURE p1;
diff --git a/mysql-test/main/greedy_optimizer.result b/mysql-test/main/greedy_optimizer.result
index 40add445c3c..2bf67d5f6d8 100644
--- a/mysql-test/main/greedy_optimizer.result
+++ b/mysql-test/main/greedy_optimizer.result
@@ -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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 1334.341393
+Last_query_cost 0.621783
set optimizer_prune_level=0;
select @@optimizer_prune_level;
@@optimizer_prune_level
@@ -198,108 +198,108 @@ select @@optimizer_search_depth;
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;
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 t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3
+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 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 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
show status like 'Last_query_cost';
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;
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 t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3
+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 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 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';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 662.822751
+Last_query_cost 0.453844
set optimizer_search_depth=1;
select @@optimizer_search_depth;
@@optimizer_search_depth
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;
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 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 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 t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost';
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;
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 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 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 t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost';
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;
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 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
+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 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 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)
show status like 'Last_query_cost';
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;
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 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 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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 1767.523851
+Last_query_cost 1.698747
set optimizer_search_depth=62;
select @@optimizer_search_depth;
@@optimizer_search_depth
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;
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 t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3
+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 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 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
show status like 'Last_query_cost';
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;
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 t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3
+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 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 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';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 662.822751
+Last_query_cost 0.453844
set optimizer_prune_level=2;
select @@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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-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 t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-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 where
-1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 1334.341393
+Last_query_cost 0.621783
set optimizer_search_depth=1;
select @@optimizer_search_depth;
@@optimizer_search_depth
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;
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 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 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 t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost';
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;
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 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 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 t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost';
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;
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 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
+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 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 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)
show status like 'Last_query_cost';
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;
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 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 1767.523851
+Last_query_cost 1.698747
set optimizer_search_depth=62;
select @@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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
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
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-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 t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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
@@ -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)
show status like 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 6
-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 where
-1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 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 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 t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 1334.341393
+Last_query_cost 0.621783
drop table t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1 (a int, b int, d int, i int);
INSERT INTO t1 VALUES (1,1,1,1);
@@ -1195,13 +1195,13 @@ COUNT(*)
9000
### NOTE: Handler_reads: 9030, expected: 9045 ###
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;
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 y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join)
-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;
COUNT(*)
90000
@@ -1209,9 +1209,9 @@ flush status;
EXPLAIN SELECT COUNT(*) FROM t10,t10000 x,t10000 y
WHERE x.k=t10.i;
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 y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join)
SELECT COUNT(*) FROM t10,t10000 x,t10000 y
WHERE x.k=t10.i;
COUNT(*)
@@ -1220,9 +1220,9 @@ flush status;
EXPLAIN SELECT COUNT(*) FROM t10,t10000 y,t10000 x
WHERE x.k=t10.i;
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 y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join)
SELECT COUNT(*) FROM t10,t10000 y,t10000 x
WHERE x.k=t10.i;
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;
show status like "optimizer%";
Variable_name Value
-Optimizer_join_prefixes_check_calls 60210
+Optimizer_join_prefixes_check_calls 63164
SET OPTIMIZER_SEARCH_DEPTH = DEFAULT;
#
# Bug found when testing greedy optimizer tests
diff --git a/mysql-test/main/greedy_optimizer.test b/mysql-test/main/greedy_optimizer.test
index f2731087cd8..04f765e815a 100644
--- a/mysql-test/main/greedy_optimizer.test
+++ b/mysql-test/main/greedy_optimizer.test
@@ -662,7 +662,7 @@ WHERE t100.K=t10.I
## Expect this QEP, cost & #handler_read
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y)
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;
--source include/expect_qep.inc
diff --git a/mysql-test/main/group_by.result b/mysql-test/main/group_by.result
index 460a3cd9357..95ec41c048b 100644
--- a/mysql-test/main/group_by.result
+++ b/mysql-test/main/group_by.result
@@ -1718,7 +1718,7 @@ NULL
insert into t2 SELECT NULL, NULL from seq_1_to_10;
EXPLAIN SELECT b from t2 GROUP BY a;
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
analyze table t2;
Table Op Msg_type Msg_text
@@ -2263,11 +2263,11 @@ INSERT INTO t2(col1, col2) VALUES
explain
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
-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
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
-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
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
@@ -2275,7 +2275,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain
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
-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
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
diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result
index c1030cf9271..f97f6d41ab2 100644
--- a/mysql-test/main/group_min_max.result
+++ b/mysql-test/main/group_min_max.result
@@ -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
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
-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:
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
@@ -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
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
-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:
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;
@@ -2230,7 +2230,7 @@ a
BB
EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a;
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;
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
@@ -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;
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
-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;
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
-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;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
@@ -2388,7 +2388,7 @@ MIN(b) a
2 1
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
-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;
MIN(c)
2
@@ -2678,7 +2678,7 @@ a b
3 13
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
-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:
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;
@@ -3579,7 +3579,7 @@ a c COUNT(DISTINCT c, a, b)
EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2
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
-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
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
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');
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
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;
f1 COUNT(DISTINCT f2)
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
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
-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";
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;
#
# 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;
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
-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;
MIN(a)
0
diff --git a/mysql-test/main/group_min_max.test b/mysql-test/main/group_min_max.test
index 3fe951b7817..d230cd15749 100644
--- a/mysql-test/main/group_min_max.test
+++ b/mysql-test/main/group_min_max.test
@@ -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
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
+
SELECT COUNT(DISTINCT c, a, b) FROM t2
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
diff --git a/mysql-test/main/group_min_max_innodb.result b/mysql-test/main/group_min_max_innodb.result
index 9671e835934..2b42ac1cbe1 100644
--- a/mysql-test/main/group_min_max_innodb.result
+++ b/mysql-test/main/group_min_max_innodb.result
@@ -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);
explain select distinct f1 a, f1 b from t1;
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;
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;
create table t1(pk int primary key) engine=innodb;
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');
EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
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';
COUNT(DISTINCT a)
1
@@ -118,7 +118,7 @@ ENGINE=InnoDB;
INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd');
EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
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';
COUNT(DISTINCT a)
1
@@ -162,7 +162,7 @@ ANALYZE TABLE t2;
EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F')
GROUP BY c1;
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')
GROUP BY c1;
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))
GROUP BY c1;
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))
GROUP BY c1;
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 )
GROUP BY c1;
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 )
GROUP BY c1;
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 )))
GROUP BY c1;
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
WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 )))
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 )
GROUP BY c1,i1;
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
WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )
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 ))
GROUP BY c1,i1;
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
WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ))
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 ))
GROUP BY c1,i1;
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
WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 ))
GROUP BY c1,i1;
diff --git a/mysql-test/main/ignored_index.result b/mysql-test/main/ignored_index.result
index 03748d48098..176ca61decd 100644
--- a/mysql-test/main/ignored_index.result
+++ b/mysql-test/main/ignored_index.result
@@ -255,17 +255,15 @@ DROP TABLE t1;
# IGNORED fulltext indexes.
#
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
-INSERT INTO t1 VALUES('Some data', 'for full-text search');
-ANALYZE TABLE t1;
-Table Op Msg_type Msg_text
-test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze Warning Engine-independent statistics are not collected for column 'b'
-test.t1 analyze status OK
-EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections");
+INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come");
+SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
+a b
+Some data for full-text search
+EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
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
DROP TABLE t1;
#
diff --git a/mysql-test/main/ignored_index.test b/mysql-test/main/ignored_index.test
index a3d46fe6046..b2fadcd5862 100644
--- a/mysql-test/main/ignored_index.test
+++ b/mysql-test/main/ignored_index.test
@@ -222,13 +222,11 @@ DROP TABLE t1;
--echo # IGNORED fulltext indexes.
--echo #
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
-INSERT INTO t1 VALUES('Some data', 'for full-text search');
-ANALYZE TABLE t1;
-
-let $query=
-EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections");
+INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come");
+let $query=SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
--eval $query
+--eval EXPLAIN $query
ALTER TABLE t1 ALTER INDEX a IGNORED;
--error ER_FT_MATCHING_KEY_NOT_FOUND
diff --git a/mysql-test/main/index_intersect.result b/mysql-test/main/index_intersect.result
index 1f31636860f..c6332591ff5 100644
--- a/mysql-test/main/index_intersect.result
+++ b/mysql-test/main/index_intersect.result
@@ -75,7 +75,7 @@ EXPLAIN
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 300000;
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
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 7000000;
@@ -712,7 +712,7 @@ EXPLAIN
SELECT * FROM City
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
-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
SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%';
diff --git a/mysql-test/main/index_intersect_innodb.result b/mysql-test/main/index_intersect_innodb.result
index efe74389119..2aba9dc6fcf 100644
--- a/mysql-test/main/index_intersect_innodb.result
+++ b/mysql-test/main/index_intersect_innodb.result
@@ -378,7 +378,7 @@ EXPLAIN
SELECT * FROM City
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
-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 ()
WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
ID Name Country Population
@@ -469,12 +469,12 @@ EXPLAIN
SELECT * FROM City
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
-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
SELECT * FROM City
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
-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
SELECT * FROM City
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
AND Country BETWEEN 'S' AND 'Z' ;
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 ()
WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
ID Name Country Population
@@ -708,7 +708,7 @@ EXPLAIN
SELECT * FROM City WHERE
Name LIKE 'M%' AND Population > 1500000;
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
SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%';
@@ -723,13 +723,13 @@ EXPLAIN
SELECT * FROM City
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
-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
SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z';
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
Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
diff --git a/mysql-test/main/index_merge_innodb.result b/mysql-test/main/index_merge_innodb.result
index d9be08a0540..6f1daf7552c 100644
--- a/mysql-test/main/index_merge_innodb.result
+++ b/mysql-test/main/index_merge_innodb.result
@@ -582,7 +582,7 @@ set @tmp_index_merge_ror_cpk=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
explain select * from t1 where pk1 < 7500 and key1 = 10;
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;
explain select * from t1 where pktail1ok=1 and key1=10;
id select_type table type possible_keys key key_len ref rows Extra
@@ -654,7 +654,7 @@ f1
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;
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
DROP TABLE t1,t2;
#
@@ -827,13 +827,13 @@ INDEX (b)
INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_100;
EXPLAIN SELECT * FROM t1 WHERE a='1' OR b < 5;
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;
a b c
+1 1 1
2 2 2
3 3 3
4 4 4
-1 1 1
DROP TABLE t1;
SET sort_buffer_size= @save_sort_buffer_size;
disconnect disable_purge;
diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result
index 30bda34ec0b..2c84086d17d 100644
--- a/mysql-test/main/index_merge_myisam.result
+++ b/mysql-test/main/index_merge_myisam.result
@@ -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
explain select key7 from t2 where key1 <100 or key2 < 100;
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 (
key1a 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)
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
-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 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 A ALL i1,i2,i3,i4,i5,i6,i7?,i8 NULL NULL NULL # Using where
+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)
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)
@@ -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
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
-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;
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
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
-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;
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
@@ -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)
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
-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
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
@@ -1558,7 +1558,7 @@ This should be intersect:
set optimizer_switch=default;
explain select * from t1 where a=10 and b=10;
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:
set optimizer_switch='default,index_merge=off,rowid_filter=off';
explain select * from t1 where a=10 and b=10;
diff --git a/mysql-test/main/information_schema-big.result b/mysql-test/main/information_schema-big.result
index 5c519014800..94c8d274fad 100644
--- a/mysql-test/main/information_schema-big.result
+++ b/mysql-test/main/information_schema-big.result
@@ -37,6 +37,7 @@ INDEX_STATISTICS TABLE_SCHEMA
KEYWORDS WORD
KEY_CACHES KEY_CACHE_NAME
KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
+OPTIMIZER_COSTS ENGINE
PARAMETERS SPECIFIC_SCHEMA
PARTITIONS TABLE_SCHEMA
PLUGINS PLUGIN_NAME
@@ -97,6 +98,7 @@ INDEX_STATISTICS TABLE_SCHEMA
KEYWORDS WORD
KEY_CACHES KEY_CACHE_NAME
KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
+OPTIMIZER_COSTS ENGINE
PARAMETERS SPECIFIC_SCHEMA
PARTITIONS TABLE_SCHEMA
PLUGINS PLUGIN_NAME
diff --git a/mysql-test/main/information_schema.result b/mysql-test/main/information_schema.result
index e46014e44b9..0c952886d63 100644
--- a/mysql-test/main/information_schema.result
+++ b/mysql-test/main/information_schema.result
@@ -71,6 +71,7 @@ INDEX_STATISTICS
KEYWORDS
KEY_CACHES
KEY_COLUMN_USAGE
+OPTIMIZER_COSTS
OPTIMIZER_TRACE
PARAMETERS
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
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
-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
set optimizer_switch=@tmp_optimizer_switch;
drop view v1;
diff --git a/mysql-test/main/innodb_ext_key,off.rdiff b/mysql-test/main/innodb_ext_key,off.rdiff
index 274d1cc47e4..8a1a251e88f 100644
--- a/mysql-test/main/innodb_ext_key,off.rdiff
+++ b/mysql-test/main/innodb_ext_key,off.rdiff
@@ -5,16 +5,13 @@
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
-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;
select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01';
count(*)
-@@ -17,9 +17,9 @@
- show status like 'handler_read%';
- Variable_name Value
+@@ -19,7 +19,7 @@
Handler_read_first 0
--Handler_read_key 1
-+Handler_read_key 2
+ Handler_read_key 1
Handler_read_last 0
-Handler_read_next 1
+Handler_read_next 6
@@ -98,16 +95,13 @@
where l_shipdate='1992-07-01' and l_orderkey=130;
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 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;
select max(l_linenumber) from lineitem
where l_shipdate='1992-07-01' and l_orderkey=130;
-@@ -143,9 +143,9 @@
- show status like 'handler_read%';
- Variable_name Value
+@@ -145,7 +145,7 @@
Handler_read_first 0
--Handler_read_key 1
-+Handler_read_key 2
+ Handler_read_key 1
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 6
@@ -178,7 +172,7 @@
where l_partkey between 1 and 10 group by l_partkey;
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
++1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 NULL # Using where; Using index
flush status;
select max(l_orderkey) from lineitem
where l_partkey between 1 and 10 group by l_partkey;
@@ -236,17 +230,17 @@
Handler_read_retry 0
Handler_read_rnd 0
@@ -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;
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 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 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;
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where
@@ -255,7 +249,7 @@
drop table t1,t2,t3;
#
# 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)
where index_date_updated= 10 and index_id < 800;
id select_type table type possible_keys key key_len ref rows Extra
@@ -271,7 +265,7 @@
drop table t0,t1,t2;
#
# MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff'
-@@ -766,13 +766,14 @@
+@@ -769,11 +769,12 @@
{
"table": {
"table_name": "t1",
@@ -285,12 +279,9 @@
+ "used_key_parts": ["f2"],
+ "ref": ["const"],
"rows": 1,
-- "filtered": 50,
-+ "filtered": 100,
+ "filtered": 100,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
- "attached_condition": "t1.f1 <= '3'"
- }
-@@ -799,8 +800,8 @@
+@@ -806,8 +807,8 @@
"access_type": "range",
"possible_keys": ["k1"],
"key": "k1",
@@ -299,5 +290,5 @@
+ "key_length": "3007",
+ "used_key_parts": ["pk1", "f2"],
"rows": 1,
- "filtered": 50,
+ "filtered": 100,
"index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'",
diff --git a/mysql-test/main/innodb_ext_key.result b/mysql-test/main/innodb_ext_key.result
index 62b143726b2..ad27ad6b5ea 100644
--- a/mysql-test/main/innodb_ext_key.result
+++ b/mysql-test/main/innodb_ext_key.result
@@ -308,15 +308,15 @@ Handler_read_rnd_next 0
# when extended_keys=on
#
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);
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;
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 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;
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
@@ -381,17 +381,18 @@ INSERT INTO t2 VALUES
(10), (11), (12), (13), (14),
(15), (16), (17), (18), (19), (24);
EXPLAIN
-SELECT a FROM t1 AS t, t2
-WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b);
+SELECT a FROM t1 AS t, t2 as t2_out
+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
-1 PRIMARY t index a,b b 7 NULL 10 Using index
-1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t.a 1 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; FirstMatch(t2)
-SELECT a FROM t1 AS t, t2
-WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b);
+1 PRIMARY t1 index b b 7 NULL 10 Using index; Start temporary
+1 PRIMARY t ref a,b b 3 test.t1.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_out eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index
+SELECT a FROM t1 AS t, t2 as t2_out
+WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b);
a
24
+Last_query_cost 0.119652
DROP TABLE t1,t2;
#
# 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
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
-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;
a
3
@@ -774,7 +775,7 @@ EXPLAIN
"key_length": "3070",
"used_key_parts": ["f2", "pk1"],
"rows": 1,
- "filtered": 50,
+ "filtered": 100,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
"attached_condition": "t1.f1 <= '3'"
}
@@ -808,7 +809,7 @@ EXPLAIN
"key_length": "3011",
"used_key_parts": ["pk1", "f2", "pk2"],
"rows": 1,
- "filtered": 50,
+ "filtered": 100,
"index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'",
"attached_condition": "t1.f1 <= '3'"
}
diff --git a/mysql-test/main/innodb_ext_key.test b/mysql-test/main/innodb_ext_key.test
index 41a55232001..2b868154bd3 100644
--- a/mysql-test/main/innodb_ext_key.test
+++ b/mysql-test/main/innodb_ext_key.test
@@ -4,6 +4,7 @@
--source include/innodb_prefix_index_cluster_optimization.inc
--source include/no_valgrind_without_big.inc
+--source include/have_sequence.inc
SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB';
@@ -156,14 +157,14 @@ show status like 'handler_read%';
--echo #
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);
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;
-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;
drop table t0;
@@ -240,10 +241,11 @@ INSERT INTO t2 VALUES
(15), (16), (17), (18), (19), (24);
EXPLAIN
-SELECT a FROM t1 AS t, t2
- WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b);
-SELECT a FROM t1 AS t, t2
- WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b);
+SELECT a FROM t1 AS t, t2 as t2_out
+ 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 as t2_out
+ 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;
diff --git a/mysql-test/main/innodb_icp.result b/mysql-test/main/innodb_icp.result
index e08faa142cf..bdbc2f6ccc1 100644
--- a/mysql-test/main/innodb_icp.result
+++ b/mysql-test/main/innodb_icp.result
@@ -414,7 +414,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
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;
#
#
@@ -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
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 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
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
@@ -455,9 +455,10 @@ c1 INT NOT NULL,
PRIMARY KEY (pk)
);
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);
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';
SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1
@@ -465,6 +466,17 @@ pk c1
2 7
4 3
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;
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));
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)));
INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
@@ -816,6 +827,8 @@ test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
SET @save_optimize_switch=@@optimizer_switch;
SET optimizer_switch='materialization=on';
+set @save_optimizer_where_cost=@@optimizer_where_cost;
+set @@optimizer_where_cost=1;
EXPLAIN
SELECT COUNT(*) FROM t1 AS t, t2
WHERE c = g
@@ -839,6 +852,7 @@ OR a = 0 AND h < 'z' );
COUNT(*)
1478
SET optimizer_switch=@save_optimizer_switch;
+set @@optimizer_where_cost=@save_optimizer_where_cost;
DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables
CREATE TABLE t1 (
diff --git a/mysql-test/main/innodb_mysql_lock2.test b/mysql-test/main/innodb_mysql_lock2.test
index 09298a900b1..e5bb4bd9565 100644
--- a/mysql-test/main/innodb_mysql_lock2.test
+++ b/mysql-test/main/innodb_mysql_lock2.test
@@ -833,6 +833,7 @@ insert into t1 values (1), (2), (3), (4), (5);
begin;
--echo # Acquire SR metadata lock on t1.
+--sorted_result
select * from t1;
connection con1;
diff --git a/mysql-test/main/invisible_field_debug.result b/mysql-test/main/invisible_field_debug.result
index 344a0b860fc..8cc1ee4db9c 100644
--- a/mysql-test/main/invisible_field_debug.result
+++ b/mysql-test/main/invisible_field_debug.result
@@ -346,7 +346,7 @@ invisible a b
9 7 7
explain select * from t1 where invisible =9;
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;
select invisible, a ,b from t1;
invisible a b
@@ -368,11 +368,11 @@ drop index invisible on t1;
ERROR 42000: Can't DROP INDEX `invisible`; check that it exists
explain select * from t1 where invisible =9;
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);
explain select * from t1 where invisible =9;
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;
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
diff --git a/mysql-test/main/join.result b/mysql-test/main/join.result
index b56f35f475e..c35ec009587 100644
--- a/mysql-test/main/join.result
+++ b/mysql-test/main/join.result
@@ -65,7 +65,7 @@ id id
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;
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
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
@@ -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;
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
-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
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);
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;
@@ -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
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 3.508545
+Last_query_cost 0.011600
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^
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
Z
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;
id select_type table type possible_keys key key_len ref rows Extra
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
show status like 'Last_query_cost';
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;
Z
^^: 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;
CREATE TABLE t1 (a INT PRIMARY KEY, b 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
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
-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
FLUSH STATUS;
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_%';
Variable_name Value
Handler_read_first 0
-Handler_read_key 0
+Handler_read_key 1
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 4
+Handler_read_rnd_next 1
DROP TABLE t1, t2;
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)
ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t4 ALL NULL NULL NULL NULL 4
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 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)
+1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
+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 (incremental, BNL join)
EXPLAIN
SELECT *
@@ -1340,9 +1346,9 @@ FROM t4 STRAIGHT_JOIN
ON t4.ref_t1=t1.c1;
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 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 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;
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 D system PRIMARY 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 8 const,test.DT.t_id,func 1 Using index
+1 SIMPLE DSA ref PRIMARY PRIMARY 4 const 3 Using where; 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
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;
diff --git a/mysql-test/main/join.test b/mysql-test/main/join.test
index a3756af023a..dfe92ff9561 100644
--- a/mysql-test/main/join.test
+++ b/mysql-test/main/join.test
@@ -685,7 +685,7 @@ drop table t1, t2, t3;
# BUG#14940 {Wrong query plan is chosen because of odd results of
# 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);
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;
-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;
show status like 'Last_query_cost';
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;
#
diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result
index 2c5323a7795..0f7ad1d23f7 100644
--- a/mysql-test/main/join_cache.result
+++ b/mysql-test/main/join_cache.result
@@ -894,7 +894,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2;
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 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
SELECT City.Name, Country.Name, CountryLanguage.Language
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
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 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
SELECT City.Name, Country.Name, CountryLanguage.Language
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
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 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
FROM City,Country,CountryLanguage
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
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 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
FROM City,Country,CountryLanguage
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 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 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,
t8.name AS artistName, t8.artistid,
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;
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
-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
SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 t1 ref idx2 idx2 3 test.t3.v 5 Using where
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
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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 t1 ref idx2 idx2 3 test.t3.v 5 Using where
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
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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 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 t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
+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; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
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
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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 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 t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
+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; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
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
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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join)
-1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join)
+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 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
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;
@@ -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
GROUP BY t2.v ORDER BY t1.pk,t2.v;
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 t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join)
-1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join)
+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 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
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;
@@ -5120,7 +5120,7 @@ EXPLAIN
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);
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)
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);
@@ -5130,7 +5130,7 @@ EXPLAIN
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);
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)
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);
@@ -6035,12 +6035,12 @@ f1 f2
EXPLAIN EXTENDED SELECT * FROM temp
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
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 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 temp ALL NULL NULL NULL NULL 7 100.00
+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 t2 hash_index v1 #hash#v1:v1 4:9 test.t1.v1 10 33.33 Using index; Using join buffer (flat, BNLH join)
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;
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
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
-1 SIMPLE t2 index PRIMARY PRIMARY 12 NULL 2 Using index
-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 t1 ALL NULL NULL NULL NULL 2 Using where
+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;
set join_cache_level=@save_join_cache_level;
#
@@ -6258,7 +6258,7 @@ EXPLAIN
{
"table": {
"table_name": "a",
- "access_type": "index",
+ "access_type": "range",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
@@ -6279,7 +6279,7 @@ EXPLAIN
"key_length": "10",
"used_key_parts": ["kp1", "kp2"],
"rows": 836,
- "filtered": 76,
+ "filtered": 9.090909004,
"index_condition": "b.kp2 <= 10",
"attached_condition": "b.kp2 <= 10 and b.col1 + 1 < 33333"
},
diff --git a/mysql-test/main/join_nested.result b/mysql-test/main/join_nested.result
index 1f8ffccf16b..96f4372ee14 100644
--- a/mysql-test/main/join_nested.result
+++ b/mysql-test/main/join_nested.result
@@ -1062,7 +1062,7 @@ t0.b=t1.b AND
(t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1);
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 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
@@ -1284,8 +1284,8 @@ NULL 2 2
DELETE FROM t3;
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
-1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition
-1 SIMPLE t2 const b 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 0 Impossible ON condition
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;
a b c
diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result
index c5386983ceb..a62bba19f16 100644
--- a/mysql-test/main/join_nested_jcl6.result
+++ b/mysql-test/main/join_nested_jcl6.result
@@ -652,7 +652,6 @@ t0.b=t1.b AND
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 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 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)
@@ -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 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 t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
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
FROM t9;
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
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 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 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)
@@ -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 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 t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
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 t5 VALUES (-3,11,0), (-2,12,0), (-3,13,0), (-4,12,0);
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
(t9.a=1);
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 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)
@@ -1293,8 +1293,8 @@ NULL 2 2
DELETE FROM t3;
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
-1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition
-1 SIMPLE t2 const b 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 0 Impossible ON condition
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;
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
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 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
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5
@@ -2120,9 +2120,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra
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 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
FROM t5 LEFT JOIN
(t6 LEFT JOIN t7 ON t7.a=1, t8)
@@ -2137,9 +2137,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra
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 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
FROM t5 LEFT JOIN
(t6 LEFT JOIN t7 ON t7.b=2, t8)
@@ -2154,9 +2154,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra
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 join buffer (incremental, 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 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
FROM t5 LEFT JOIN
(t8, t6 LEFT JOIN t7 ON t7.a=1)
diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result
index eb5bf0e1700..6ed5114ea5b 100644
--- a/mysql-test/main/join_outer.result
+++ b/mysql-test/main/join_outer.result
@@ -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;
id select_type table type possible_keys key key_len ref rows Extra
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
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
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;
id select_type table type possible_keys key key_len ref rows Extra
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
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
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
@a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a),
-IF(@a<450, NULL, @a)
+IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C;
delete from t1 where a=0;
# 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
explain select * from t2 force index (c) where c is null;
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;
id select_type table type possible_keys key key_len ref rows Extra
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;
id select_type table type possible_keys key key_len ref rows Extra
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;
#
# MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause
diff --git a/mysql-test/main/join_outer.test b/mysql-test/main/join_outer.test
index ac4207a720a..8e4c343f247 100644
--- a/mysql-test/main/join_outer.test
+++ b/mysql-test/main/join_outer.test
@@ -1813,7 +1813,7 @@ create table t2 (a int, b int, c int, key(b), key(c));
insert into t2 select
@a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a),
- IF(@a<450, NULL, @a)
+ IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C;
delete from t1 where a=0;
diff --git a/mysql-test/main/join_outer_innodb.result b/mysql-test/main/join_outer_innodb.result
index 5373dbc0bbc..dc3a8bdb1f6 100644
--- a/mysql-test/main/join_outer_innodb.result
+++ b/mysql-test/main/join_outer_innodb.result
@@ -435,46 +435,48 @@ left join t16 on t15.o1 = t16.p1
where t1.a10 = 1;
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 t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index
-1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; 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
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 t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 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
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 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 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 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 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 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
explain select * from v1;
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 t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index
-1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; 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
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 t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 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
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 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 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 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 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 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
drop view v1;
drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
diff --git a/mysql-test/main/join_outer_jcl6.result b/mysql-test/main/join_outer_jcl6.result
index 5c88511b020..eeb22c2c5ac 100644
--- a/mysql-test/main/join_outer_jcl6.result
+++ b/mysql-test/main/join_outer_jcl6.result
@@ -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;
id select_type table type possible_keys key key_len ref rows Extra
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
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
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;
id select_type table type possible_keys key key_len ref rows Extra
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
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
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
@a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a),
-IF(@a<450, NULL, @a)
+IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C;
delete from t1 where a=0;
# 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
explain select * from t2 force index (c) where c is null;
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;
id select_type table type possible_keys key key_len ref rows Extra
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;
id select_type table type possible_keys key key_len ref rows Extra
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;
#
# 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;
id select_type table type possible_keys key key_len ref rows Extra
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 join buffer (incremental, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, 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.
#
diff --git a/mysql-test/main/key.result b/mysql-test/main/key.result
index 42d57a35531..e6bb46af2b1 100644
--- a/mysql-test/main/key.result
+++ b/mysql-test/main/key.result
@@ -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
SHOW STATUS LIKE 'Last_query_cost';
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;
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
SHOW STATUS LIKE 'Last_query_cost';
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL a 5 NULL 6
SHOW STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.014749
+Last_query_cost 0.014784
DROP TABLE t1;
#
# MDEV-21480: Unique key using ref access though eq_ref access can be used
diff --git a/mysql-test/main/key_cache.result b/mysql-test/main/key_cache.result
index 3edbac8c9ae..4ec0d6ab7d7 100644
--- a/mysql-test/main/key_cache.result
+++ b/mysql-test/main/key_cache.result
@@ -434,7 +434,7 @@ p i a
3 1 yyyy
4 3 zzzz
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';
VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
@@ -482,7 +482,7 @@ p i a
3 1 yyyy
4 3 zzzz
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';
VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
@@ -527,7 +527,7 @@ p i a
3 1 yyyy
4 3 zzzz
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';
VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
@@ -583,7 +583,7 @@ p i a
3 1 yyyy
4 3 zzzz
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;
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
@@ -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
default 2 NULL 32768 1024 # # 0 6749 # 3684 103
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 status;
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;
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
@@ -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%"
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
-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;
cache index t2 in keycache2;
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%"
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
-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
cache index t2 in keycache1;
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
default 2 NULL 32768 1024 # # 0 3172 24 1552 18
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
set global keycache1.key_cache_block_size=2*1024;
insert into t2 values (7000, 3, 'yyyy');
diff --git a/mysql-test/main/key_cache.test b/mysql-test/main/key_cache.test
index 9bd57f017f0..baca5c07fec 100644
--- a/mysql-test/main/key_cache.test
+++ b/mysql-test/main/key_cache.test
@@ -299,7 +299,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
select * from t1;
select * from t2;
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 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 t2;
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 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 t2;
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 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 t2;
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 #
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 #
select * from information_schema.key_caches where segment_number is null;
+analyze table t2;
flush tables; flush status;
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 #
select * from information_schema.key_caches where segment_number is null;
diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result
index e87dd25cac9..9d3d5bbf0ab 100644
--- a/mysql-test/main/limit_rows_examined.result
+++ b/mysql-test/main/limit_rows_examined.result
@@ -211,51 +211,48 @@ explain
select * from t1
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
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
select * from t1
where c1 IN (select * from t2 where c2 > ' ' 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
+cc
+dd
explain
select * from t1
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
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
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
+cc
+dd
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
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
+cc
+dd
explain
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 6;
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
select * from t1i
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;
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
-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
where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17;
c1
@@ -416,24 +413,22 @@ c1
bb
cc
dd
-select * from v1 LIMIT ROWS EXAMINED 17;
+select * from v1 LIMIT ROWS EXAMINED 10;
c1
bb
cc
dd
-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
-select * from v1 LIMIT ROWS EXAMINED 16;
+select * from v1 LIMIT ROWS EXAMINED 8;
c1
bb
cc
+dd
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
-select * from v1 LIMIT ROWS EXAMINED 11;
+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 3;
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
+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
drop view v1;
explain
select *
@@ -441,17 +436,16 @@ from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 2 func 1
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
select *
from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
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
+cc
+dd
=========================================================================
Aggregation
=========================================================================
diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test
index 2315580410f..512058e1eb6 100644
--- a/mysql-test/main/limit_rows_examined.test
+++ b/mysql-test/main/limit_rows_examined.test
@@ -277,9 +277,9 @@ create view v1 as
select * from t1 where c1 IN (select * from t2 where c2 > ' ');
select * from v1;
-select * from v1 LIMIT ROWS EXAMINED 17;
-select * from v1 LIMIT ROWS EXAMINED 16;
-select * from v1 LIMIT ROWS EXAMINED 11;
+select * from v1 LIMIT ROWS EXAMINED 10;
+select * from v1 LIMIT ROWS EXAMINED 8;
+select * from v1 LIMIT ROWS EXAMINED 3;
drop view v1;
diff --git a/mysql-test/main/mrr_derived_crash_4610.result b/mysql-test/main/mrr_derived_crash_4610.result
index 3e38a0d4218..d7800e8a2a9 100644
--- a/mysql-test/main/mrr_derived_crash_4610.result
+++ b/mysql-test/main/mrr_derived_crash_4610.result
@@ -7,7 +7,7 @@ explain select 1 from
(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;
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
2 DERIVED t4 ALL NULL NULL NULL NULL 1
2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result
index aae3ea173b7..864939bbda8 100644
--- a/mysql-test/main/myisam.result
+++ b/mysql-test/main/myisam.result
@@ -648,6 +648,9 @@ insert into t1 values (1,''), (2,'');
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 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;
create table t1 (c1 int, c2 varchar(4) not null default '',
key(c2(3))) default charset=utf8;
diff --git a/mysql-test/main/myisam.test b/mysql-test/main/myisam.test
index 32b74027b14..53c5f9843cc 100644
--- a/mysql-test/main/myisam.test
+++ b/mysql-test/main/myisam.test
@@ -595,6 +595,7 @@ explain select count(*) from t1 where a is null;
select count(*) from t1 where a is null;
insert into t1 values (1,''), (2,'');
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;
#
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 98bb644fd5f..0b81b1d85b9 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -256,7 +256,7 @@ FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY 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)
Warnings:
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);
CREATE TABLE t2 (b INT);
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)
-# select: SELECT * FROM t1, t2 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 t3 WHERE t3.b < 3)
#
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
-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
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
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 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
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
-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
Variable_name Value
-Handler_read_key 4
+Handler_read_key 6
FLUSH STATUS;
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
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 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:
-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
Variable_name Value
-Handler_read_key 4
+Handler_read_key 6
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
# Status of "equivalent" SELECT query execution:
Variable_name Value
-Handler_read_key 7
-Handler_read_rnd_next 14
+Handler_read_key 9
+Handler_read_rnd_next 1014
# Status of testing query execution:
Variable_name Value
-Handler_read_key 7
-Handler_read_rnd_next 19
+Handler_read_key 9
+Handler_read_rnd_next 1019
Handler_update 2
-DROP TABLE t1, t2;
+DROP TABLE t1, t2, t3;
#8
CREATE TABLE t1 (a INT);
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
EXPLAIN DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 Using where; Using filesort
+1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 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
Variable_name Value
Handler_read_key 3
@@ -818,11 +821,8 @@ Handler_read_next 3
# Status of testing query execution:
Variable_name Value
Handler_delete 3
-Handler_read_key 3
-Handler_read_rnd 3
-Handler_read_rnd_next 7
-Sort_rows 3
-Sort_scan 1
+Handler_read_key 4
+Handler_read_next 3
DROP TABLE t1;
#17
@@ -1003,10 +1003,9 @@ FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
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
Variable_name Value
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
# Status of "equivalent" SELECT query execution:
Variable_name Value
-Handler_read_key 7
+Handler_read_key 4
Handler_read_rnd_next 9
# Status of testing query execution:
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);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ref IDX IDX 5 test.t1.f1 2
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
-2 DEPENDENT SUBQUERY t2 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:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
# 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;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
-2 DEPENDENT SUBQUERY t2 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:
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`
@@ -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
# Status of "equivalent" SELECT query execution:
Variable_name Value
-Handler_read_key 9
-Handler_read_rnd_next 9
+Handler_read_key 11
+Handler_read_next 2
+Handler_read_rnd_next 3
# Status of testing query execution:
Variable_name Value
-Handler_read_key 7
-Handler_read_rnd_next 9
+Handler_read_key 9
+Handler_read_next 2
+Handler_read_rnd_next 3
Handler_update 2
DROP TABLE t1, t2;
diff --git a/mysql-test/main/myisam_icp.result b/mysql-test/main/myisam_icp.result
index 5dfa61effef..2ffd2d9ad4b 100644
--- a/mysql-test/main/myisam_icp.result
+++ b/mysql-test/main/myisam_icp.result
@@ -407,7 +407,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
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;
#
#
@@ -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);
id select_type table type possible_keys key key_len ref rows Extra
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 t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join)
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);
pk i
@@ -448,9 +448,10 @@ c1 INT NOT NULL,
PRIMARY KEY (pk)
);
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);
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';
SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1
@@ -458,6 +459,17 @@ pk c1
2 7
4 3
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;
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);
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 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
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(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));
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)));
INSERT INTO t2 VALUES
('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)
HAVING t1.c != 5 ORDER BY t1.c;
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 t2 ref a a 515 test.t1.a # Using where
+1 SIMPLE t1 system PRIMARY NULL NULL NULL #
+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)
HAVING t1.c != 5 ORDER BY t1.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)
HAVING t1.c != 5 ORDER BY t1.c;
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 t2 ref a a 515 test.t1.a # Using where
+1 SIMPLE t1 system PRIMARY NULL NULL NULL #
+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)
HAVING t1.c != 5 ORDER BY t1.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
SET @save_optimize_switch=@@optimizer_switch;
SET optimizer_switch='materialization=on';
+set @save_optimizer_where_cost=@@optimizer_where_cost;
+set @@optimizer_where_cost=1;
EXPLAIN
SELECT COUNT(*) FROM t1 AS t, t2
WHERE c = g
@@ -832,6 +845,7 @@ OR a = 0 AND h < 'z' );
COUNT(*)
1478
SET optimizer_switch=@save_optimizer_switch;
+set @@optimizer_where_cost=@save_optimizer_where_cost;
DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables
CREATE TABLE t1 (
diff --git a/mysql-test/main/myisam_mrr.result b/mysql-test/main/myisam_mrr.result
index b758b2b3258..6bf72e688bc 100644
--- a/mysql-test/main/myisam_mrr.result
+++ b/mysql-test/main/myisam_mrr.result
@@ -517,7 +517,7 @@ table3.col_varchar_key = table2.col_varchar_nokey AND
table3.pk<>0;
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 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_buffer_size= @save_join_buffer_size;
drop table t1;
@@ -572,8 +572,7 @@ Handler_mrr_rowid_refills 0
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, filler char(200), key(a));
-insert into t1
-select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
+insert into t1 select seq, 123, 'filler' from seq_0_to_14999;
explain select sum(b) from t1 where a < 10;
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
diff --git a/mysql-test/main/myisam_mrr.test b/mysql-test/main/myisam_mrr.test
index 11c9aa64ef1..601844ab385 100644
--- a/mysql-test/main/myisam_mrr.test
+++ b/mysql-test/main/myisam_mrr.test
@@ -1,6 +1,8 @@
#
# MRR/MyISAM tests.
#
+--source include/have_sequence.inc
+
--disable_warnings
drop table if exists t0, t1, t2, t3;
@@ -278,8 +280,7 @@ show status like 'Handler_mrr%';
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, filler char(200), key(a));
-insert into t1
-select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
+insert into t1 select seq, 123, 'filler' from seq_0_to_14999;
explain select sum(b) from t1 where a < 10;
--echo # This should show one MRR scan and no re-fills:
diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result
index 9a098312eb2..ad1343fa779 100644
--- a/mysql-test/main/mysqld--help.result
+++ b/mysql-test/main/mysqld--help.result
@@ -764,6 +764,10 @@ The following specify which files/extra groups are read (specified before remain
key.
--optimizer-row-next-find-cost=#
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=#
Extra cost added to TABLE and INDEX scans to get
optimizer to prefer index lookups.
@@ -1748,6 +1752,8 @@ optimizer-prune-level 2
optimizer-row-copy-cost 6.0866e-05
optimizer-row-lookup-cost 0.000130839
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-search-depth 62
optimizer-selectivity-sampling-limit 100
diff --git a/mysql-test/main/named_pipe.result b/mysql-test/main/named_pipe.result
index 2baa3471ec9..a0738cdad34 100644
--- a/mysql-test/main/named_pipe.result
+++ b/mysql-test/main/named_pipe.result
@@ -1,5 +1,6 @@
connect pipe_con,localhost,root,,,,,PIPE;
drop table if exists t1,t2,t3,t4;
+set @@default_storage_engine="aria";
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' 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
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
+#
+# Some test with ORDER BY and limit
+#
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
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 '',
PRIMARY KEY (companynr),
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;
companynr companyname
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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
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;
id select_type table type possible_keys key key_len ref rows Extra
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
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
-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
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
-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
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
-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
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
@@ -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
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
-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
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
-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
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
diff --git a/mysql-test/main/negation_elimination.result b/mysql-test/main/negation_elimination.result
index 0ad23e547b0..7b9a76d86b2 100644
--- a/mysql-test/main/negation_elimination.result
+++ b/mysql-test/main/negation_elimination.result
@@ -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);
explain select * from t1 where not(not(a));
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));
a
1
@@ -55,7 +55,7 @@ a
10
explain select * from t1 where not(a = 10);
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);
a
0
@@ -500,7 +500,7 @@ NULL NULL
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));
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:
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;
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index ea8d6139920..35cae556d92 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -118,8 +118,8 @@ select * from v1 {
"table": "t1",
"table_scan": {
"rows": 2,
- "read_cost": 1.002197266,
- "read_and_compare_cost": 1.502197266
+ "read_cost": 0.01028441,
+ "read_and_compare_cost": 0.01034841
}
}
]
@@ -139,18 +139,18 @@ select * from v1 {
{
"access_type": "scan",
"rows": 2,
- "rows_after_scan": 1,
"rows_after_filter": 1,
- "cost": 1.502197266,
+ "rows_out": 1,
+ "cost": 0.01034841,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 1,
- "records_out": 1,
- "cost": 1.502197266,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.01034841,
"uses_join_buffering": false
}
}
@@ -161,14 +161,14 @@ select * from v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 1.502197266
+ "cost_for_plan": 0.01034841
}
]
},
{
"best_join_order": ["t1"],
"rows": 1,
- "cost": 1.502197266
+ "cost": 0.01034841
},
{
"substitute_best_equal": {
@@ -286,8 +286,8 @@ select * from (select * from t1 where t1.a=1)q {
"table": "t1",
"table_scan": {
"rows": 2,
- "read_cost": 1.002197266,
- "read_and_compare_cost": 1.502197266
+ "read_cost": 0.01028441,
+ "read_and_compare_cost": 0.01034841
}
}
]
@@ -307,18 +307,18 @@ select * from (select * from t1 where t1.a=1)q {
{
"access_type": "scan",
"rows": 2,
- "rows_after_scan": 1,
"rows_after_filter": 1,
- "cost": 1.502197266,
+ "rows_out": 1,
+ "cost": 0.01034841,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 1,
- "records_out": 1,
- "cost": 1.502197266,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.01034841,
"uses_join_buffering": false
}
}
@@ -329,14 +329,14 @@ select * from (select * from t1 where t1.a=1)q {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 1.502197266
+ "cost_for_plan": 0.01034841
}
]
},
{
"best_join_order": ["t1"],
"rows": 1,
- "cost": 1.502197266
+ "cost": 0.01034841
},
{
"substitute_best_equal": {
@@ -459,8 +459,8 @@ select * from v2 {
"table": "t1",
"table_scan": {
"rows": 2,
- "read_cost": 1.002197266,
- "read_and_compare_cost": 1.502197266
+ "read_cost": 0.01028441,
+ "read_and_compare_cost": 0.01034841
}
}
]
@@ -480,9 +480,9 @@ select * from v2 {
{
"access_type": "scan",
"rows": 2,
- "rows_after_scan": 1,
"rows_after_filter": 1,
- "cost": 1.502197266,
+ "rows_out": 1,
+ "cost": 0.01034841,
"index_only": false,
"chosen": true,
"use_tmp_table": true
@@ -490,9 +490,9 @@ select * from v2 {
],
"chosen_access_method": {
"type": "scan",
- "records_read": 1,
- "records_out": 1,
- "cost": 1.502197266,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.01034841,
"uses_join_buffering": false
}
}
@@ -503,15 +503,15 @@ select * from v2 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 1.502197266,
- "cost_for_sorting": 1
+ "cost_for_plan": 0.01034841,
+ "cost_for_sorting": 6.301866e-4
}
]
},
{
"best_join_order": ["t1"],
"rows": 1,
- "cost": 2.502197266
+ "cost": 0.010978597
},
{
"substitute_best_equal": {
@@ -549,8 +549,8 @@ select * from v2 {
"table": "<derived2>",
"table_scan": {
"rows": 2,
- "read_cost": 2,
- "read_and_compare_cost": 2.5
+ "read_cost": 0.012350033,
+ "read_and_compare_cost": 0.012418701
}
}
]
@@ -570,18 +570,18 @@ select * from v2 {
{
"access_type": "scan",
"rows": 2,
- "rows_after_scan": 2,
"rows_after_filter": 2,
- "cost": 2.5,
+ "rows_out": 2,
+ "cost": 0.012418701,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 2,
- "records_out": 2,
- "cost": 2.5,
+ "rows_read": 2,
+ "rows_out": 2,
+ "cost": 0.012418701,
"uses_join_buffering": false
}
}
@@ -592,14 +592,14 @@ select * from v2 {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 2,
- "cost_for_plan": 2.5
+ "cost_for_plan": 0.012418701
}
]
},
{
"best_join_order": ["<derived2>"],
"rows": 2,
- "cost": 2.5
+ "cost": 0.012418701
},
{
"attaching_conditions_to_tables": {
@@ -703,8 +703,8 @@ explain select * from v2 {
"table": "t2",
"table_scan": {
"rows": 10,
- "read_cost": 1.010986328,
- "read_and_compare_cost": 3.510986328
+ "read_cost": 0.01127965,
+ "read_and_compare_cost": 0.01159965
}
}
]
@@ -724,18 +724,18 @@ explain select * from v2 {
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 10,
"rows_after_filter": 10,
- "cost": 3.510986328,
+ "rows_out": 10,
+ "cost": 0.01159965,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.510986328,
+ "rows_read": 10,
+ "rows_out": 10,
+ "cost": 0.01159965,
"uses_join_buffering": false
}
}
@@ -746,14 +746,14 @@ explain select * from v2 {
"plan_prefix": [],
"table": "t2",
"rows_for_plan": 10,
- "cost_for_plan": 3.510986328
+ "cost_for_plan": 0.01159965
}
]
},
{
"best_join_order": ["t2"],
"rows": 10,
- "cost": 3.510986328
+ "cost": 0.01159965
},
{
"attaching_conditions_to_tables": {
@@ -836,8 +836,8 @@ explain select * from v1 {
"table": "t1",
"table_scan": {
"rows": 10,
- "read_cost": 1.010986328,
- "read_and_compare_cost": 3.510986328
+ "read_cost": 0.01127965,
+ "read_and_compare_cost": 0.01159965
}
}
]
@@ -857,9 +857,9 @@ explain select * from v1 {
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 10,
"rows_after_filter": 10,
- "cost": 3.510986328,
+ "rows_out": 10,
+ "cost": 0.01159965,
"index_only": false,
"chosen": true,
"use_tmp_table": true
@@ -867,9 +867,9 @@ explain select * from v1 {
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.510986328,
+ "rows_read": 10,
+ "rows_out": 10,
+ "cost": 0.01159965,
"uses_join_buffering": false
}
}
@@ -880,15 +880,15 @@ explain select * from v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 10,
- "cost_for_plan": 3.510986328,
- "cost_for_sorting": 10
+ "cost_for_plan": 0.01159965,
+ "cost_for_sorting": 0.006368384
}
]
},
{
"best_join_order": ["t1"],
"rows": 10,
- "cost": 13.51098633
+ "cost": 0.017968034
},
{
"attaching_conditions_to_tables": {
@@ -920,8 +920,8 @@ explain select * from v1 {
"table": "<derived2>",
"table_scan": {
"rows": 10,
- "read_cost": 10,
- "read_and_compare_cost": 12.5
+ "read_cost": 0.012414166,
+ "read_and_compare_cost": 0.012757506
}
}
]
@@ -941,18 +941,18 @@ explain select * from v1 {
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 10,
"rows_after_filter": 10,
- "cost": 12.5,
+ "rows_out": 10,
+ "cost": 0.012757506,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 12.5,
+ "rows_read": 10,
+ "rows_out": 10,
+ "cost": 0.012757506,
"uses_join_buffering": false
}
}
@@ -963,14 +963,14 @@ explain select * from v1 {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 10,
- "cost_for_plan": 12.5
+ "cost_for_plan": 0.012757506
}
]
},
{
"best_join_order": ["<derived2>"],
"rows": 10,
- "cost": 12.5
+ "cost": 0.012757506
},
{
"attaching_conditions_to_tables": {
@@ -1102,16 +1102,16 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"table": "t1",
"table_scan": {
"rows": 100,
- "read_cost": 1.158691406,
- "read_and_compare_cost": 26.15869141
+ "read_cost": 0.0224761,
+ "read_and_compare_cost": 0.0256761
}
},
{
"table": "t2",
"table_scan": {
"rows": 100,
- "read_cost": 1.158691406,
- "read_and_compare_cost": 26.15869141
+ "read_cost": 0.0224761,
+ "read_and_compare_cost": 0.0256761
}
}
]
@@ -1131,18 +1131,18 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"access_type": "scan",
"rows": 100,
- "rows_after_scan": 100,
"rows_after_filter": 100,
- "cost": 26.15869141,
+ "rows_out": 100,
+ "cost": 0.0256761,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 100,
- "records_out": 100,
- "cost": 26.15869141,
+ "rows_read": 100,
+ "rows_out": 100,
+ "cost": 0.0256761,
"uses_join_buffering": false
}
}
@@ -1157,18 +1157,18 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"access_type": "scan",
"rows": 100,
- "rows_after_scan": 100,
"rows_after_filter": 100,
- "cost": 26.15869141,
+ "rows_out": 100,
+ "cost": 0.0256761,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 100,
- "records_out": 100,
- "cost": 26.15869141,
+ "rows_read": 100,
+ "rows_out": 100,
+ "cost": 0.0256761,
"uses_join_buffering": false
}
}
@@ -1179,7 +1179,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 100,
- "cost_for_plan": 26.15869141,
+ "cost_for_plan": 0.0256761,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -1197,24 +1197,24 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cost": 125.0585794,
+ "cost": 0.1731074,
"chosen": true
},
{
"access_type": "scan_with_join_cache",
"rows": 100,
- "rows_after_scan": 75,
- "rows_after_filter": 75,
- "cost": 1807.408691,
+ "rows_after_filter": 100,
+ "rows_out": 1,
+ "cost": 0.9604227,
"index_only": false,
"chosen": false
}
],
"chosen_access_method": {
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 125.0585794,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.1731074,
"uses_join_buffering": false
}
}
@@ -1225,7 +1225,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": ["t1"],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 151.2172709
+ "cost_for_plan": 0.1987835
}
]
},
@@ -1233,7 +1233,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": [],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 26.15869141,
+ "cost_for_plan": 0.0256761,
"rest_of_plan": [
{
"plan_prefix": ["t2"],
@@ -1251,24 +1251,24 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cost": 125.0585794,
+ "cost": 0.1731074,
"chosen": true
},
{
"access_type": "scan_with_join_cache",
"rows": 100,
- "rows_after_scan": 75,
- "rows_after_filter": 75,
- "cost": 1807.408691,
+ "rows_after_filter": 100,
+ "rows_out": 1,
+ "cost": 0.9604227,
"index_only": false,
"chosen": false
}
],
"chosen_access_method": {
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 125.0585794,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.1731074,
"uses_join_buffering": false
}
}
@@ -1279,10 +1279,10 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": ["t2"],
"table": "t1",
"rows_for_plan": 100,
- "cost_for_plan": 151.2172709,
+ "cost_for_plan": 0.1987835,
"pruned_by_cost": true,
- "current_cost": 151.2172709,
- "best_cost": 151.2173709
+ "current_cost": 0.1987835,
+ "best_cost": 0.1987835
}
]
}
@@ -1291,7 +1291,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"best_join_order": ["t1", "t2"],
"rows": 100,
- "cost": 151.2172709
+ "cost": 0.1987835
},
{
"substitute_best_equal": {
@@ -1330,10 +1330,11 @@ drop table t1,t2,t0;
# group_by min max optimization
#
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, KEY(a));
+insert into t1 select seq, mod(seq,4)+1 from seq_1_to_65536;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze status OK
+test.t1 analyze status Table is already up to date
EXPLAIN SELECT DISTINCT a FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL a 4 NULL 5 Using index for group-by
@@ -1372,7 +1373,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"range_analysis": {
"table_scan": {
"rows": 65536,
- "cost": 16457
+ "cost": 10.29477568
},
"potential_range_indexes": [
{
@@ -1388,7 +1389,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 14898.29141,
+ "cost": 9.123706862,
"chosen": true
},
"group_index_range": {
@@ -1398,7 +1399,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"index": "a",
"covering": true,
"rows": 5,
- "cost": 6.5
+ "cost": 0.004191135
}
]
},
@@ -1410,7 +1411,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 5,
- "cost": 6.5,
+ "cost": 0.004191135,
"key_parts_used_for_access": ["a"],
"ranges": [],
"chosen": true
@@ -1424,12 +1425,12 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 5,
- "cost": 6.5,
+ "cost": 0.004191135,
"key_parts_used_for_access": ["a"],
"ranges": []
},
"rows_for_plan": 5,
- "cost_for_plan": 6.5,
+ "cost_for_plan": 0.004191135,
"chosen": true
}
}
@@ -1451,17 +1452,17 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
{
"access_type": "index_merge",
"rows": 5,
- "rows_after_scan": 5,
"rows_after_filter": 5,
- "cost": 6.5,
+ "rows_out": 5,
+ "cost": 0.004191135,
"chosen": true
}
],
"chosen_access_method": {
"type": "index_merge",
- "records_read": 5,
- "records_out": 5,
- "cost": 6.5,
+ "rows_read": 5,
+ "rows_out": 5,
+ "cost": 0.004191135,
"uses_join_buffering": false
}
}
@@ -1472,14 +1473,14 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 5,
- "cost_for_plan": 6.5
+ "cost_for_plan": 0.004191135
}
]
},
{
"best_join_order": ["t1"],
"rows": 5,
- "cost": 6.5
+ "cost": 0.004191135
},
{
"attaching_conditions_to_tables": {
@@ -1515,10 +1516,13 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a;
id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range NULL a 20 NULL 7 Using where; Using index for group-by
+set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a;
+id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL a 20 NULL 7 Using where; Using index
select * from information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
-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 {
"steps": [
{
"join_preparation": {
@@ -1574,7 +1578,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"range_analysis": {
"table_scan": {
"rows": 7,
- "cost": 2.764526367
+ "cost": 0.001130435
},
"potential_range_indexes": [
{
@@ -1585,8 +1589,9 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 2.084226263,
- "chosen": true
+ "cost": 0.001758432,
+ "chosen": false,
+ "cause": "cost"
},
"setup_range_conditions": [],
"analyzing_range_alternatives": {
@@ -1603,7 +1608,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"covering": true,
"ranges": ["(2,3) <= (b,c) <= (2,3)"],
"rows": 7,
- "cost": 2.75
+ "cost": 0.004425189
}
]
},
@@ -1615,7 +1620,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 7,
- "cost": 2.75,
+ "cost": 0.004425189,
"key_parts_used_for_access": ["a", "b", "c"],
"ranges": ["(2,3) <= (b,c) <= (2,3)"],
"chosen": false,
@@ -1656,9 +1661,9 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
{
"access_type": "scan",
"rows": 7,
- "rows_after_scan": 1,
"rows_after_filter": 1,
- "cost": 2.084226263,
+ "rows_out": 0.571428573,
+ "cost": 0.001758432,
"index_only": true,
"chosen": true,
"use_tmp_table": true
@@ -1666,9 +1671,9 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
],
"chosen_access_method": {
"type": "scan",
- "records_read": 1,
- "records_out": 0.571428573,
- "cost": 2.084226263,
+ "rows_read": 1,
+ "rows_out": 0.571428573,
+ "cost": 0.001758432,
"uses_join_buffering": false
}
}
@@ -1678,16 +1683,19 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
{
"plan_prefix": [],
"table": "t1",
- "rows_for_plan": 1,
- "cost_for_plan": 2.084226263,
- "cost_for_sorting": 1
+ "rows_for_plan": 0.571428573,
+ "cost_for_plan": 0.001758432,
+ "pushdown_cond_selectivity": 0.571428573,
+ "filtered": 8.163265322,
+ "rows_out": 0.571428573,
+ "cost_for_sorting": 3.585611e-4
}
]
},
{
"best_join_order": ["t1"],
- "rows": 1,
- "cost": 3.084226263
+ "rows": 0.571428573,
+ "cost": 0.002116993
},
{
"substitute_best_equal": {
@@ -1711,8 +1719,8 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"clause": "GROUP BY",
"table": "t1",
"rows_estimation": 1,
- "read_cost": 2.147624763,
- "filesort_cost": 0.0633985,
+ "filesort_cost": 4.579083e-5,
+ "read_cost": 0.001804223,
"filesort_type": "priority_queue with addon fields",
"fanout": 1,
"possible_keys": [
@@ -1722,7 +1730,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"direction": 1,
"rows_to_examine": 7,
"range_scan": false,
- "scan_cost": 2.084226263,
+ "scan_cost": 0.001667847,
"chosen": true
}
]
@@ -1811,7 +1819,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"range_analysis": {
"table_scan": {
"rows": 16,
- "cost": 5.015625
+ "cost": 0.01253808
},
"potential_range_indexes": [
{
@@ -1822,7 +1830,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
],
"best_covering_index_scan": {
"index": "id",
- "cost": 4.11171589,
+ "cost": 0.008002862,
"chosen": true
},
"setup_range_conditions": [],
@@ -1840,7 +1848,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"covering": true,
"ranges": ["(2001-01-04) <= (a)"],
"rows": 9,
- "cost": 3.25
+ "cost": 0.005620843
}
]
},
@@ -1852,7 +1860,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"max_aggregate": true,
"distinct_aggregate": false,
"rows": 9,
- "cost": 3.25,
+ "cost": 0.005620843,
"key_parts_used_for_access": ["id"],
"ranges": ["(2001-01-04) <= (a)"],
"chosen": true
@@ -1866,12 +1874,12 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"max_aggregate": true,
"distinct_aggregate": false,
"rows": 9,
- "cost": 3.25,
+ "cost": 0.005620843,
"key_parts_used_for_access": ["id"],
"ranges": ["(2001-01-04) <= (a)"]
},
"rows_for_plan": 9,
- "cost_for_plan": 3.25,
+ "cost_for_plan": 0.005620843,
"chosen": true
}
}
@@ -1893,18 +1901,18 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
{
"access_type": "index_merge",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25,
+ "rows_out": 9,
+ "cost": 0.005620843,
"chosen": true,
"use_tmp_table": true
}
],
"chosen_access_method": {
"type": "index_merge",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.005620843,
"uses_join_buffering": false
}
}
@@ -1915,15 +1923,15 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 9,
- "cost_for_plan": 3.25,
- "cost_for_sorting": 9
+ "cost_for_plan": 0.005620843,
+ "cost_for_sorting": 0.005728198
}
]
},
{
"best_join_order": ["t1"],
"rows": 9,
- "cost": 12.25
+ "cost": 0.011349041
},
{
"substitute_best_equal": {
@@ -2014,7 +2022,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"range_analysis": {
"table_scan": {
"rows": 16,
- "cost": 5.015625
+ "cost": 0.01253808
},
"potential_range_indexes": [
{
@@ -2025,7 +2033,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
],
"best_covering_index_scan": {
"index": "id",
- "cost": 4.11171589,
+ "cost": 0.008002862,
"chosen": true
},
"setup_range_conditions": [],
@@ -2043,7 +2051,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"covering": true,
"ranges": ["(2001-01-04) <= (a) <= (2001-01-04)"],
"rows": 9,
- "cost": 3.25
+ "cost": 0.005620843
}
]
},
@@ -2055,7 +2063,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 9,
- "cost": 3.25,
+ "cost": 0.005620843,
"key_parts_used_for_access": ["id", "a"],
"ranges": ["(2001-01-04) <= (a) <= (2001-01-04)"],
"chosen": true
@@ -2069,12 +2077,12 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 9,
- "cost": 3.25,
+ "cost": 0.005620843,
"key_parts_used_for_access": ["id", "a"],
"ranges": ["(2001-01-04) <= (a) <= (2001-01-04)"]
},
"rows_for_plan": 9,
- "cost_for_plan": 3.25,
+ "cost_for_plan": 0.005620843,
"chosen": true
}
}
@@ -2096,18 +2104,18 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
{
"access_type": "index_merge",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25,
+ "rows_out": 9,
+ "cost": 0.005620843,
"chosen": true,
"use_tmp_table": true
}
],
"chosen_access_method": {
"type": "index_merge",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.005620843,
"uses_join_buffering": false
}
}
@@ -2118,15 +2126,15 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 9,
- "cost_for_plan": 3.25,
- "cost_for_sorting": 9
+ "cost_for_plan": 0.005620843,
+ "cost_for_sorting": 0.005728198
}
]
},
{
"best_join_order": ["t1"],
"rows": 9,
- "cost": 12.25
+ "cost": 0.011349041
},
{
"substitute_best_equal": {
@@ -2160,10 +2168,6 @@ drop table t1;
#
# Late ORDER BY optimization
#
-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 (
pk int not null,
a int,
@@ -2174,19 +2178,18 @@ KEY c(c),
KEY a_c(a,c),
KEY a_b(a,b)
);
-insert into t1
-select a, a,a,a, 'filler-dataaa' from test.one_k;
+insert into t1 select seq, seq,seq,seq, 'filler-dataaa' from seq_0_to_999;
update t1 set a=1 where pk between 0 and 180;
update t1 set b=2 where pk between 0 and 20;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
-set optimizer_trace='enabled=on';
explain select * from t1 where a=1 and b=2 order by c limit 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a_c,a_b a_b 10 const,const 21 Using where; Using filesort
update t1 set b=2 where pk between 20 and 40;
+set optimizer_trace='enabled=on';
explain select * from t1 where a=1 and b=2 order by c limit 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a_c,a_b a_c 5 NULL 180 Using where
@@ -2270,7 +2273,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 265.2822266
+ "cost": 0.1731718
},
"potential_range_indexes": [
{
@@ -2299,8 +2302,9 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 180,
- "cost": 135.6693776,
- "chosen": true
+ "cost": 0.223346519,
+ "chosen": false,
+ "cause": "cost"
},
{
"index": "a_b",
@@ -2309,7 +2313,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 41,
- "cost": 31.3040249,
+ "cost": 0.051838728,
"chosen": true
}
],
@@ -2330,7 +2334,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"ranges": ["(1,2) <= (a,b) <= (1,2)"]
},
"rows_for_plan": 41,
- "cost_for_plan": 31.3040249,
+ "cost_for_plan": 0.051838728,
"chosen": true
}
}
@@ -2340,12 +2344,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"rowid_filters": [
{
"key": "a_b",
- "build_cost": 1.752281351,
+ "build_cost": 6.9153e-4,
"rows": 41
},
{
"key": "a_c",
- "build_cost": 6.264109827,
+ "build_cost": 0.0040552,
"rows": 180
}
]
@@ -2390,7 +2394,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"index": "a_c",
"used_range_estimates": true,
"rows": 180,
- "cost": 135.6493776,
+ "cost": 0.222796377,
"chosen": true
},
{
@@ -2398,7 +2402,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"index": "a_b",
"used_range_estimates": true,
"rows": 41,
- "cost": 31.2840249,
+ "cost": 0.051288586,
"chosen": true
},
{
@@ -2409,9 +2413,9 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
],
"chosen_access_method": {
"type": "ref",
- "records_read": 41,
- "records_out": 41,
- "cost": 31.2840249,
+ "rows_read": 41,
+ "rows_out": 41,
+ "cost": 0.051288586,
"uses_join_buffering": false
}
}
@@ -2422,14 +2426,14 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 41,
- "cost_for_plan": 31.2840249
+ "cost_for_plan": 0.051288586
}
]
},
{
"best_join_order": ["t1"],
"rows": 41,
- "cost": 31.2840249
+ "cost": 0.051288586
},
{
"substitute_best_equal": {
@@ -2453,8 +2457,8 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"clause": "ORDER BY",
"table": "t1",
"rows_estimation": 41,
- "read_cost": 32.58369415,
- "filesort_cost": 1.299669251,
+ "filesort_cost": 9.387121e-4,
+ "read_cost": 0.052227298,
"filesort_type": "priority_queue with addon fields",
"fanout": 1,
"possible_keys": [
@@ -2464,7 +2468,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"direction": 1,
"rows_to_examine": 24,
"range_scan": false,
- "scan_cost": 18.51405907,
+ "scan_cost": 0.030312813,
"chosen": true
},
{
@@ -2473,7 +2477,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"direction": 1,
"rows_to_examine": 4.390243902,
"range_scan": true,
- "scan_cost": 11.5484164,
+ "scan_cost": 0.023380552,
"chosen": true
},
{
@@ -2487,10 +2491,6 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
{
"table": "t1",
"range_analysis": {
- "table_scan": {
- "rows": 1000,
- "cost": 1.79769e308
- },
"potential_range_indexes": [
{
"index": "c",
@@ -2518,7 +2518,8 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 180,
- "cost": 135.6693776,
+ "cost": 0.223346519,
+ "cost_with_limit": 0.002483968,
"chosen": true
}
],
@@ -2539,7 +2540,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"ranges": ["(1) <= (a) <= (1)"]
},
"rows_for_plan": 180,
- "cost_for_plan": 135.6693776,
+ "cost_for_plan": 0.223346519,
"chosen": true
}
}
@@ -2555,7 +2556,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
}
]
} 0 0
-drop table t1,ten,one_k;
+drop table t1;
#
# TABLE ELIMINATION
#
@@ -2646,8 +2647,8 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"table": "t1",
"table_scan": {
"rows": 4,
- "read_cost": 1.003417969,
- "read_and_compare_cost": 2.003417969
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
},
{
@@ -2673,18 +2674,18 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
{
"access_type": "scan",
"rows": 4,
- "rows_after_scan": 4,
"rows_after_filter": 4,
- "cost": 2.003417969,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 4,
- "records_out": 4,
- "cost": 2.003417969,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
@@ -2695,14 +2696,14 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"plan_prefix": ["t2"],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 2.003417969
+ "cost_for_plan": 0.01066122
}
]
},
{
"best_join_order": ["t2", "t1"],
"rows": 4,
- "cost": 2.003417969
+ "cost": 0.01066122
},
{
"substitute_best_equal": {
@@ -2802,16 +2803,16 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"table": "t1",
"table_scan": {
"rows": 4,
- "read_cost": 1.003417969,
- "read_and_compare_cost": 2.003417969
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
},
{
"table": "t2",
"table_scan": {
"rows": 2,
- "read_cost": 1.002197266,
- "read_and_compare_cost": 1.502197266
+ "read_cost": 0.01028441,
+ "read_and_compare_cost": 0.01034841
}
}
]
@@ -2831,18 +2832,18 @@ explain select * from t1 left join t2 on t2.a=t1.a {
{
"access_type": "scan",
"rows": 4,
- "rows_after_scan": 4,
"rows_after_filter": 4,
- "cost": 2.003417969,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 4,
- "records_out": 4,
- "cost": 2.003417969,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
@@ -2853,7 +2854,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 2.003417969,
+ "cost_for_plan": 0.01066122,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -2869,24 +2870,20 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"access_type": "eq_ref",
"index": "PRIMARY",
"rows": 1,
- "cost": 5.002147913,
+ "cost": 0.007120904,
"chosen": true
},
{
- "access_type": "scan",
- "rows": 2,
- "rows_after_scan": 1.5,
- "rows_after_filter": 1.5,
- "cost": 6.008789062,
- "index_only": false,
- "chosen": false
+ "type": "scan",
+ "chosen": false,
+ "cause": "cost"
}
],
"chosen_access_method": {
"type": "eq_ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 5.002147913,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.007120904,
"uses_join_buffering": false
}
}
@@ -2897,7 +2894,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"plan_prefix": ["t1"],
"table": "t2",
"rows_for_plan": 4,
- "cost_for_plan": 7.005565882
+ "cost_for_plan": 0.017782124
}
]
}
@@ -2906,7 +2903,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
{
"best_join_order": ["t1", "t2"],
"rows": 4,
- "cost": 7.005565882
+ "cost": 0.017782124
},
{
"substitute_best_equal": {
@@ -3043,8 +3040,8 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"table": "t1",
"table_scan": {
"rows": 4,
- "read_cost": 1.003417969,
- "read_and_compare_cost": 2.003417969
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
},
{
@@ -3076,18 +3073,18 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
{
"access_type": "scan",
"rows": 4,
- "rows_after_scan": 4,
"rows_after_filter": 4,
- "cost": 2.003417969,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 4,
- "records_out": 4,
- "cost": 2.003417969,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
@@ -3098,14 +3095,14 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"plan_prefix": ["t3", "t2"],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 2.003417969
+ "cost_for_plan": 0.01066122
}
]
},
{
"best_join_order": ["t3", "t2", "t1"],
"rows": 4,
- "cost": 2.003417969
+ "cost": 0.01066122
},
{
"substitute_best_equal": {
@@ -3143,33 +3140,27 @@ drop table t0, t1, t2, t3;
#
# IN subquery to sem-join is traced
#
-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);
-insert into t1 values (0,0),(1,1),(2,2);
-create table t2 as select * from t1;
-create table t11(a int, b int);
-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;
-Table Op Msg_type Msg_text
-test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze status OK
-test.t10 analyze status Engine-independent statistics collected
-test.t10 analyze status OK
+insert into t1 select seq,seq from seq_0_to_3;
+create table t2 (p int, a int);
+insert into t2 select seq,seq from seq_1_to_10;
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);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 10 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`p` = `test`.`t1`.`a`
+insert into t2 select seq,seq from seq_10_to_100;
+explain extended select * from t1 where a in (select p from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t10 ALL NULL NULL NULL NULL 10 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t10`) where 1
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`p` = `test`.`t1`.`a`
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
-explain extended select * from t1 where a in (select pk from t10) {
+explain extended select * from t1 where a in (select p from t2) {
"steps": [
{
"join_preparation": {
@@ -3188,13 +3179,13 @@ explain extended select * from t1 where a in (select pk from t10) {
}
},
{
- "expanded_query": "/* select#2 */ select t10.pk from t10"
+ "expanded_query": "/* select#2 */ select t2.p from t2"
}
]
}
},
{
- "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from t1 where t1.a in (/* select#2 */ select t10.pk from t10)"
+ "expanded_query": "/* select#1 */ select t1.a AS a,t1.b AS b from t1 where t1.a in (/* select#2 */ select t2.p from t2)"
}
]
}
@@ -3223,19 +3214,19 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"condition_processing": {
"condition": "WHERE",
- "original_condition": "1 and t1.a = t10.pk",
+ "original_condition": "1 and t1.a = t2.p",
"steps": [
{
"transformation": "equality_propagation",
- "resulting_condition": "1 and multiple equal(t1.a, t10.pk)"
+ "resulting_condition": "1 and multiple equal(t1.a, t2.p)"
},
{
"transformation": "constant_propagation",
- "resulting_condition": "1 and multiple equal(t1.a, t10.pk)"
+ "resulting_condition": "1 and multiple equal(t1.a, t2.p)"
},
{
"transformation": "trivial_condition_removal",
- "resulting_condition": "multiple equal(t1.a, t10.pk)"
+ "resulting_condition": "multiple equal(t1.a, t2.p)"
}
]
}
@@ -3249,7 +3240,7 @@ explain extended select * from t1 where a in (select pk from t10) {
"depends_on_map_bits": []
},
{
- "table": "t10",
+ "table": "t2",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": []
@@ -3264,17 +3255,17 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"table": "t1",
"table_scan": {
- "rows": 3,
- "read_cost": 1.003295898,
- "read_and_compare_cost": 1.753295898
+ "rows": 4,
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
},
{
- "table": "t10",
+ "table": "t2",
"table_scan": {
- "rows": 10,
- "read_cost": 1.010986328,
- "read_and_compare_cost": 3.510986328
+ "rows": 101,
+ "read_cost": 0.022600505,
+ "read_and_compare_cost": 0.025832505
}
}
]
@@ -3294,26 +3285,26 @@ explain extended select * from t1 where a in (select pk from t10) {
"get_costs_for_tables": [
{
"best_access_path": {
- "table": "t10",
+ "table": "t2",
"plan_details": {
"record_count": 1
},
"considered_access_paths": [
{
"access_type": "scan",
- "rows": 10,
- "rows_after_scan": 10,
- "rows_after_filter": 10,
- "cost": 3.510986328,
+ "rows": 101,
+ "rows_after_filter": 101,
+ "rows_out": 101,
+ "cost": 0.025832505,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.510986328,
+ "rows_read": 101,
+ "rows_out": 101,
+ "cost": 0.025832505,
"uses_join_buffering": false
}
}
@@ -3322,9 +3313,9 @@ explain extended select * from t1 where a in (select pk from t10) {
},
{
"plan_prefix": [],
- "table": "t10",
- "rows_for_plan": 10,
- "cost_for_plan": 3.510986328
+ "table": "t2",
+ "rows_for_plan": 101,
+ "cost_for_plan": 0.025832505
}
]
}
@@ -3345,45 +3336,45 @@ explain extended select * from t1 where a in (select pk from t10) {
"considered_access_paths": [
{
"access_type": "scan",
- "rows": 3,
- "rows_after_scan": 3,
- "rows_after_filter": 3,
- "cost": 1.753295898,
+ "rows": 4,
+ "rows_after_filter": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.753295898,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
},
{
"best_access_path": {
- "table": "t10",
+ "table": "t2",
"plan_details": {
"record_count": 1
},
"considered_access_paths": [
{
"access_type": "scan",
- "rows": 10,
- "rows_after_scan": 10,
- "rows_after_filter": 10,
- "cost": 3.510986328,
+ "rows": 101,
+ "rows_after_filter": 101,
+ "rows_out": 101,
+ "cost": 0.025832505,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.510986328,
+ "rows_read": 101,
+ "rows_out": 101,
+ "cost": 0.025832505,
"uses_join_buffering": false
}
}
@@ -3393,8 +3384,8 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"plan_prefix": [],
"table": "t1",
- "rows_for_plan": 3,
- "cost_for_plan": 1.753295898,
+ "rows_for_plan": 4,
+ "cost_for_plan": 0.01066122,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -3402,26 +3393,26 @@ explain extended select * from t1 where a in (select pk from t10) {
"get_costs_for_tables": [
{
"best_access_path": {
- "table": "t10",
+ "table": "t2",
"plan_details": {
- "record_count": 3
+ "record_count": 4
},
"considered_access_paths": [
{
"access_type": "scan_with_join_cache",
- "rows": 10,
- "rows_after_scan": 10,
- "rows_after_filter": 10,
- "cost": 10.63598633,
+ "rows": 101,
+ "rows_after_filter": 101,
+ "rows_out": 101,
+ "cost": 0.063593833,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 10.63598633,
+ "rows_read": 101,
+ "rows_out": 101,
+ "cost": 0.063593833,
"uses_join_buffering": true
}
}
@@ -3430,40 +3421,46 @@ explain extended select * from t1 where a in (select pk from t10) {
},
{
"plan_prefix": ["t1"],
- "table": "t10",
- "rows_for_plan": 30,
- "cost_for_plan": 12.38928223,
+ "table": "t2",
+ "rows_for_plan": 404,
+ "cost_for_plan": 0.074255053,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 3,
- "cost": 12.38928223
+ "rows": 4,
+ "cost": 0.074255053
},
{
"strategy": "SJ-Materialization",
- "records": 3,
- "cost": 8.664282227
+ "rows": 4,
+ "cost": 0.078768645
},
{
"strategy": "DuplicateWeedout",
- "records": 3,
- "dups_cost": 12.38928223,
- "write_cost": 2.5,
- "full_lookup_cost": 15,
- "total_cost": 29.88928223
+ "prefix_row_count": 4,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 101,
+ "rows": 4,
+ "dups_cost": 0.074255053,
+ "write_cost": 0.02564388,
+ "full_lookup_cost": 0.06503188,
+ "total_cost": 0.164930813
},
{
- "chosen_strategy": "SJ-Materialization"
+ "chosen_strategy": "FirstMatch"
}
- ]
+ ],
+ "sj_rows_out": 1,
+ "sj_rows_for_plan": 4,
+ "sj_filtered": 0.99009901
}
]
},
{
"plan_prefix": [],
- "table": "t10",
- "rows_for_plan": 10,
- "cost_for_plan": 3.510986328,
+ "table": "t2",
+ "rows_for_plan": 101,
+ "cost_for_plan": 0.025832505,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -3472,31 +3469,51 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"fix_semijoin_strategies_for_picked_join_order": [
{
- "semi_join_strategy": "SJ-Materialization",
+ "semi_join_strategy": "FirstMatch",
"join_order": [
{
- "table": "t10"
+ "table": "t2",
+ "best_access_path": {
+ "table": "t2",
+ "plan_details": {
+ "record_count": 4
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan",
+ "rows": 101,
+ "rows_after_filter": 101,
+ "rows_out": 101,
+ "cost": 0.10333002,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 101,
+ "rows_out": 101,
+ "cost": 0.10333002,
+ "uses_join_buffering": false
+ }
+ }
}
]
}
]
},
{
- "best_join_order": ["t1", "<subquery2>"],
- "rows": 3,
- "cost": 8.664282227
+ "best_join_order": ["t1", "t2"],
+ "rows": 4,
+ "cost": 0.074255053
},
{
"substitute_best_equal": {
"condition": "WHERE",
- "resulting_condition": "1"
+ "resulting_condition": "t2.p = t1.a"
}
},
{
- "condition_on_constant_tables": "1",
- "computing_condition": []
- },
- {
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
@@ -3505,12 +3522,8 @@ explain extended select * from t1 where a in (select pk from t10) {
"attached": null
},
{
- "table": "t10",
- "attached": null
- },
- {
- "table": "<subquery2>",
- "attached": null
+ "table": "t2",
+ "attached": "t2.p = t1.a"
}
]
}
@@ -3526,12 +3539,10 @@ explain extended select * from t1 where a in (select pk from t10) {
}
]
} 0 0
-drop table t0,t1,t11,t10,t12,t2;
+drop table t1,t2;
#
# Selectivities for columns and indexes.
#
-create table t0 (a int);
-insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
pk int,
a int,
@@ -3539,7 +3550,7 @@ b int,
key pk(pk),
key pk_a(pk,a),
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 ();
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
@@ -3653,7 +3664,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 3.515869141
+ "cost": 0.01159965
},
"potential_range_indexes": [
{
@@ -3674,7 +3685,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
],
"best_covering_index_scan": {
"index": "pk_a_b",
- "cost": 2.760739566,
+ "cost": 0.007173242,
"chosen": true
},
"setup_range_conditions": [],
@@ -3687,7 +3698,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270585794,
+ "cost": 0.002483968,
"chosen": true
},
{
@@ -3697,7 +3708,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270829876,
+ "cost": 0.002483968,
"chosen": false,
"cause": "cost"
},
@@ -3708,7 +3719,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.746073957,
+ "cost": 0.001388369,
"chosen": true
}
],
@@ -3716,10 +3727,10 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"intersecting_indexes": [
{
"index": "pk",
- "index_scan_cost": 0.525585794,
- "cumulated_index_scan_cost": 0.525585794,
- "disk_sweep_cost": 0.75,
- "cumulative_total_cost": 1.275585794,
+ "index_scan_cost": 0.000806227,
+ "cumulated_index_scan_cost": 0.000806227,
+ "disk_sweep_cost": 0.001143284,
+ "cumulative_total_cost": 0.001949511,
"usable": true,
"matching_rows_now": 1,
"intersect_covering_with_this_index": false,
@@ -3757,7 +3768,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"ranges": ["(2,5,1) <= (pk,a,b) <= (2,5,1)"]
},
"rows_for_plan": 1,
- "cost_for_plan": 0.746073957,
+ "cost_for_plan": 0.001388369,
"chosen": true
}
}
@@ -3767,17 +3778,17 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"rowid_filters": [
{
"key": "pk",
- "build_cost": 0.526585794,
+ "build_cost": 0.000002653,
"rows": 1
},
{
"key": "pk_a",
- "build_cost": 0.526829876,
+ "build_cost": 0.000002653,
"rows": 1
},
{
"key": "pk_a_b",
- "build_cost": 0.527073957,
+ "build_cost": 0.000002653,
"rows": 1
}
]
@@ -3822,7 +3833,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"index": "pk",
"used_range_estimates": true,
"rows": 1,
- "cost": 1.250585794,
+ "cost": 0.001933826,
"chosen": true
},
{
@@ -3830,7 +3841,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"index": "pk_a",
"used_range_estimates": true,
"rows": 1,
- "cost": 1.250829876,
+ "cost": 0.001933826,
"chosen": false,
"cause": "cost"
},
@@ -3839,7 +3850,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"index": "pk_a_b",
"used_range_estimates": true,
"rows": 1,
- "cost": 0.726073957,
+ "cost": 0.000838227,
"chosen": true
},
{
@@ -3850,9 +3861,9 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
],
"chosen_access_method": {
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 0.726073957,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.000838227,
"uses_join_buffering": false
}
}
@@ -3863,14 +3874,14 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 0.726073957
+ "cost_for_plan": 0.000838227
}
]
},
{
"best_join_order": ["t1"],
"rows": 1,
- "cost": 0.726073957
+ "cost": 0.000838227
},
{
"substitute_best_equal": {
@@ -3902,7 +3913,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
} 0 0
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set @@use_stat_tables= @save_use_stat_tables;
-drop table t0,t1;
+drop table t1;
set optimizer_trace="enabled=off";
#
# Tests added to show that sub-statements are not traced
@@ -3966,8 +3977,8 @@ select f1(a) from t1 {
"table": "t1",
"table_scan": {
"rows": 4,
- "read_cost": 1.003417969,
- "read_and_compare_cost": 2.003417969
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
}
]
@@ -3987,18 +3998,18 @@ select f1(a) from t1 {
{
"access_type": "scan",
"rows": 4,
- "rows_after_scan": 4,
"rows_after_filter": 4,
- "cost": 2.003417969,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 4,
- "records_out": 4,
- "cost": 2.003417969,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
@@ -4009,14 +4020,14 @@ select f1(a) from t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 2.003417969
+ "cost_for_plan": 0.01066122
}
]
},
{
"best_join_order": ["t1"],
"rows": 4,
- "cost": 2.003417969
+ "cost": 0.01066122
},
{
"attaching_conditions_to_tables": {
@@ -4080,8 +4091,8 @@ select f2(a) from t1 {
"table": "t1",
"table_scan": {
"rows": 4,
- "read_cost": 1.003417969,
- "read_and_compare_cost": 2.003417969
+ "read_cost": 0.01053322,
+ "read_and_compare_cost": 0.01066122
}
}
]
@@ -4101,18 +4112,18 @@ select f2(a) from t1 {
{
"access_type": "scan",
"rows": 4,
- "rows_after_scan": 4,
"rows_after_filter": 4,
- "cost": 2.003417969,
+ "rows_out": 4,
+ "cost": 0.01066122,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 4,
- "records_out": 4,
- "cost": 2.003417969,
+ "rows_read": 4,
+ "rows_out": 4,
+ "cost": 0.01066122,
"uses_join_buffering": false
}
}
@@ -4123,14 +4134,14 @@ select f2(a) from t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 2.003417969
+ "cost_for_plan": 0.01066122
}
]
},
{
"best_join_order": ["t1"],
"rows": 4,
- "cost": 2.003417969
+ "cost": 0.01066122
},
{
"attaching_conditions_to_tables": {
@@ -4171,7 +4182,7 @@ a
2
select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
length(trace)
-2766
+2747
set optimizer_trace_max_mem_size=100;
select * from t1;
a
@@ -4185,7 +4196,7 @@ select * from t1 {
"join_preparation": {
"select_id": 1,
"steps": [
- 2666 0
+ 2647 0
set optimizer_trace_max_mem_size=0;
select * from t1;
a
@@ -4193,7 +4204,7 @@ a
2
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
-select * from t1 2766 0
+select * from t1 2747 0
drop table t1;
set optimizer_trace='enabled=off';
set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size;
@@ -4218,7 +4229,7 @@ explain delete from t0 where t0.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 3.510986328
+ "cost": 0.01159965
},
"potential_range_indexes": [
{
@@ -4237,7 +4248,7 @@ explain delete from t0 where t0.a<3 {
"using_mrr": false,
"index_only": false,
"rows": 3,
- "cost": 2.771757383,
+ "cost": 0.004951706,
"chosen": true
}
],
@@ -4255,7 +4266,7 @@ explain delete from t0 where t0.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 2.771757383,
+ "cost_for_plan": 0.004951706,
"chosen": true
}
}
@@ -4358,7 +4369,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 3.510986328
+ "cost": 0.01159965
},
"potential_range_indexes": [
{
@@ -4369,7 +4380,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 2.755857945,
+ "cost": 0.007173242,
"chosen": true
},
"setup_range_conditions": [],
@@ -4382,7 +4393,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"using_mrr": false,
"index_only": true,
"rows": 3,
- "cost": 1.196757383,
+ "cost": 0.001664909,
"chosen": true
}
],
@@ -4403,7 +4414,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 1.196757383,
+ "cost_for_plan": 0.001664909,
"chosen": true
}
}
@@ -4423,7 +4434,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 3.510986328
+ "cost": 0.01159965
},
"potential_range_indexes": [
{
@@ -4434,7 +4445,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 2.755857945,
+ "cost": 0.007173242,
"chosen": true
},
"setup_range_conditions": [],
@@ -4447,7 +4458,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"using_mrr": false,
"index_only": true,
"rows": 3,
- "cost": 1.196757383,
+ "cost": 0.001664909,
"chosen": true
}
],
@@ -4468,7 +4479,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 1.196757383,
+ "cost_for_plan": 0.001664909,
"chosen": true
}
}
@@ -4499,18 +4510,19 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"considered_access_paths": [
{
"access_type": "range",
+ "range_index": "a",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.196757383,
+ "rows_out": 3,
+ "cost": 0.001664909,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.196757383,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.001664909,
"uses_join_buffering": false
}
}
@@ -4524,18 +4536,19 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"considered_access_paths": [
{
"access_type": "range",
+ "range_index": "a",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.196757383,
+ "rows_out": 3,
+ "cost": 0.001664909,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.196757383,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.001664909,
"uses_join_buffering": false
}
}
@@ -4546,7 +4559,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": [],
"table": "t0",
"rows_for_plan": 3,
- "cost_for_plan": 1.196757383,
+ "cost_for_plan": 0.001664909,
"rest_of_plan": [
{
"plan_prefix": ["t0"],
@@ -4564,7 +4577,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"used_range_estimates": false,
"reason": "not better than ref estimates",
"rows": 1,
- "cost": 2.176757383,
+ "cost": 0.002105081,
"chosen": true
},
{
@@ -4575,9 +4588,9 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"chosen_access_method": {
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 2.176757383,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.002105081,
"uses_join_buffering": false
}
}
@@ -4588,7 +4601,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": ["t0"],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.373514767
+ "cost_for_plan": 0.00376999
}
]
},
@@ -4596,7 +4609,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 1.196757383,
+ "cost_for_plan": 0.001664909,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -4615,7 +4628,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"used_range_estimates": false,
"reason": "not better than ref estimates",
"rows": 2,
- "cost": 2.853514767,
+ "cost": 0.002519891,
"chosen": true
},
{
@@ -4626,9 +4639,9 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"chosen_access_method": {
"type": "ref",
- "records_read": 2,
- "records_out": 1.166666667,
- "cost": 2.853514767,
+ "rows_read": 2,
+ "rows_out": 2,
+ "cost": 0.002519891,
"uses_join_buffering": false
}
}
@@ -4639,10 +4652,10 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": ["t1"],
"table": "t0",
"rows_for_plan": 6,
- "cost_for_plan": 4.05027215,
+ "cost_for_plan": 0.0041848,
"pruned_by_cost": true,
- "current_cost": 4.05027215,
- "best_cost": 3.373614767
+ "current_cost": 0.0041848,
+ "best_cost": 0.00376999
}
]
}
@@ -4651,7 +4664,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
{
"best_join_order": ["t0", "t1"],
"rows": 3,
- "cost": 3.373514767
+ "cost": 0.00376999
},
{
"substitute_best_equal": {
@@ -4760,8 +4773,8 @@ explain select * from (select rand() from t1)q {
"table": "t1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -4781,18 +4794,18 @@ explain select * from (select rand() from t1)q {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -4803,14 +4816,14 @@ explain select * from (select rand() from t1)q {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477
+ "cost_for_plan": 0.010504815
}
]
},
{
"best_join_order": ["t1"],
"rows": 3,
- "cost": 1.752563477
+ "cost": 0.010504815
},
{
"attaching_conditions_to_tables": {
@@ -4842,8 +4855,8 @@ explain select * from (select rand() from t1)q {
"table": "<derived2>",
"table_scan": {
"rows": 3,
- "read_cost": 3,
- "read_and_compare_cost": 3.75
+ "read_cost": 0.01235805,
+ "read_and_compare_cost": 0.012461052
}
}
]
@@ -4863,18 +4876,18 @@ explain select * from (select rand() from t1)q {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.75,
+ "rows_out": 3,
+ "cost": 0.012461052,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.75,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.012461052,
"uses_join_buffering": false
}
}
@@ -4885,14 +4898,14 @@ explain select * from (select rand() from t1)q {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 3,
- "cost_for_plan": 3.75
+ "cost_for_plan": 0.012461052
}
]
},
{
"best_join_order": ["<derived2>"],
"rows": 3,
- "cost": 3.75
+ "cost": 0.012461052
},
{
"attaching_conditions_to_tables": {
@@ -5044,24 +5057,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"table": "t1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -5089,18 +5102,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5115,18 +5128,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5137,7 +5150,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_1"],
@@ -5152,18 +5165,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -5174,7 +5187,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953
+ "cost_for_plan": 0.022028022
}
]
},
@@ -5182,7 +5195,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"pruned_by_heuristic": true
}
]
@@ -5205,18 +5218,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5231,18 +5244,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5257,18 +5270,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5279,7 +5292,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5295,18 +5308,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -5321,18 +5334,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -5343,7 +5356,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5359,18 +5372,18 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 9.177563477,
+ "rows_out": 3,
+ "cost": 0.015203373,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 9.177563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.015203373,
"uses_join_buffering": true
}
}
@@ -5381,30 +5394,36 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 14.82019043,
+ "cost_for_plan": 0.037231395,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 3,
- "cost": 22.7833252
+ "rows": 3,
+ "cost": 0.136562595
},
{
"strategy": "SJ-Materialization",
- "records": 3,
- "cost": 10.64519043
+ "rows": 3,
+ "cost": 0.059588485
},
{
"strategy": "DuplicateWeedout",
- "records": 3,
- "dups_cost": 14.82019043,
- "write_cost": 1.45,
- "full_lookup_cost": 4.05,
- "total_cost": 20.32019043
+ "prefix_row_count": 3,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 9,
+ "rows": 3,
+ "dups_cost": 0.037231395,
+ "write_cost": 0.02548291,
+ "full_lookup_cost": 0.00434619,
+ "total_cost": 0.067060495
},
{
"chosen_strategy": "SJ-Materialization"
}
- ]
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 3,
+ "sj_filtered": 11.11111111
}
]
},
@@ -5412,7 +5431,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1"],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -5422,7 +5441,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -5430,7 +5449,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -5454,7 +5473,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_join_order": ["t1", "<subquery2>"],
"rows": 3,
- "cost": 10.64519043
+ "cost": 0.059588485
},
{
"substitute_best_equal": {
@@ -5506,11 +5525,11 @@ explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_
t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3
-1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 FirstMatch(t_outer_1); Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Start temporary; Using join buffer (incremental, BNL join)
1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (incremental, BNL join)
-1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join)
-1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t_outer_2); Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; End temporary; Using join buffer (incremental, BNL join)
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and
@@ -5669,48 +5688,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"table": "t_outer_1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_outer_2",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_inner_3",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_4",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -5745,18 +5764,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5771,18 +5790,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5797,18 +5816,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -5823,18 +5842,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -5849,18 +5868,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -5875,18 +5894,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -5897,7 +5916,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5913,18 +5932,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -5939,18 +5958,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -5965,18 +5984,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -5991,18 +6010,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -6017,18 +6036,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -6039,7 +6058,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6055,18 +6074,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 70.08269043,
+ "rows_out": 9,
+ "cost": 0.050443503,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 70.08269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.050443503,
"uses_join_buffering": true
}
}
@@ -6081,18 +6100,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 24.02756348,
+ "rows_out": 3,
+ "cost": 0.024600489,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 24.02756348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.024600489,
"uses_join_buffering": true
}
}
@@ -6107,18 +6126,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 24.02756348,
+ "rows_out": 3,
+ "cost": 0.024600489,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 24.02756348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.024600489,
"uses_join_buffering": true
}
}
@@ -6133,18 +6152,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 70.08269043,
+ "rows_out": 9,
+ "cost": 0.050443503,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 70.08269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.050443503,
"uses_join_buffering": true
}
}
@@ -6155,7 +6174,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_1",
"rows_for_plan": 81,
- "cost_for_plan": 35.45031738,
+ "cost_for_plan": 0.049238529,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6171,18 +6190,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -6197,18 +6216,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 77.69006348,
+ "rows_out": 3,
+ "cost": 0.067582275,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 77.69006348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.067582275,
"uses_join_buffering": true
}
}
@@ -6223,18 +6242,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -6245,25 +6264,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 266.5205078,
+ "cost_for_plan": 0.222053862,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 322.6148926
+ "rows": 27,
+ "cost": 1.23517089
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 266.5205078,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 380.9205078
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.222053862,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.368747182
},
{
- "chosen_strategy": "FirstMatch"
+ "chosen_strategy": "DuplicateWeedout"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
"rest_of_plan": [
{
"plan_prefix": [
@@ -6283,18 +6308,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 30.10256348,
+ "rows_out": 3,
+ "cost": 0.034460781,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 30.10256348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.034460781,
"uses_join_buffering": true
}
}
@@ -6309,18 +6334,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 88.30769043,
+ "rows_out": 9,
+ "cost": 0.080024379,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 88.30769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.080024379,
"uses_join_buffering": true
}
}
@@ -6336,7 +6361,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 352.7174561,
+ "cost_for_plan": 0.403207963,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6358,18 +6383,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -6386,25 +6411,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 638.4626465,
+ "cost_for_plan": 0.664765924,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 633.8070313
+ "rows": 27,
+ "cost": 1.579280032
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 638.4626465,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 752.8626465
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.664765924,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.811459244
},
{
- "chosen_strategy": "FirstMatch"
+ "chosen_strategy": "DuplicateWeedout"
}
- ]
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
}
]
},
@@ -6417,7 +6448,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 410.922583,
+ "cost_for_plan": 0.448771561,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6427,7 +6458,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 113.1403809,
+ "cost_for_plan": 0.116820804,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6448,18 +6479,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -6474,18 +6505,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -6501,11 +6532,86 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 881.8480713,
+ "cost_for_plan": 0.745494255,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 881.8480713,
- "best_cost": 633.8071312
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_outer_2",
+ "t_inner_1",
+ "t_inner_4",
+ "t_inner_2"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 2187
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 6.764540577,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 6.764540577,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_outer_2",
+ "t_inner_1",
+ "t_inner_4",
+ "t_inner_2"
+ ],
+ "table": "t_inner_3",
+ "rows_for_plan": 19683,
+ "cost_for_plan": 7.510034832,
+ "semijoin_strategy_choice": [
+ {
+ "strategy": "FirstMatch",
+ "rows": 27,
+ "cost": 28.96624341
+ },
+ {
+ "strategy": "DuplicateWeedout",
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 729,
+ "rows": 27,
+ "dups_cost": 7.510034832,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 3.16837251,
+ "total_cost": 10.70775353
+ },
+ {
+ "chosen_strategy": "FirstMatch"
+ }
+ ],
+ "sj_rows_out": 0.012345679,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 0.137174211,
+ "pruned_by_cost": true,
+ "current_cost": 28.96624341,
+ "best_cost": 0.811459244
+ }
+ ]
},
{
"plan_prefix": [
@@ -6516,11 +6622,9 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 881.8480713,
+ "cost_for_plan": 0.745494255,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 881.8480713,
- "best_cost": 633.8071312
+ "pruned_by_heuristic": true
}
]
},
@@ -6528,7 +6632,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 266.5205078,
+ "cost_for_plan": 0.222053862,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": "min_read_time"
}
@@ -6538,7 +6642,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 81.50544434,
+ "cost_for_plan": 0.075081543,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -6546,7 +6650,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 35.45031738,
+ "cost_for_plan": 0.049238529,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -6554,7 +6658,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 81.50544434,
+ "cost_for_plan": 0.075081543,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6564,7 +6668,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6580,18 +6684,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -6606,18 +6710,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -6632,18 +6736,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 9.177563477,
+ "rows_out": 3,
+ "cost": 0.015203373,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 9.177563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.015203373,
"uses_join_buffering": true
}
}
@@ -6658,18 +6762,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -6680,7 +6784,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6696,18 +6800,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -6722,18 +6826,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 77.69006348,
+ "rows_out": 3,
+ "cost": 0.067582275,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 77.69006348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.067582275,
"uses_join_buffering": true
}
}
@@ -6748,18 +6852,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -6770,20 +6874,26 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 262.2455078,
+ "cost_for_plan": 0.219286686,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 262.2455078,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 376.6455078
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.219286686,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.365980006
},
{
"chosen_strategy": "DuplicateWeedout"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
"rest_of_plan": [
{
"plan_prefix": [
@@ -6803,18 +6913,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 30.10256348,
+ "rows_out": 3,
+ "cost": 0.034460781,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 30.10256348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.034460781,
"uses_join_buffering": true
}
}
@@ -6829,18 +6939,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 88.30769043,
+ "rows_out": 9,
+ "cost": 0.080024379,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 88.30769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.080024379,
"uses_join_buffering": true
}
}
@@ -6856,7 +6966,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 406.7480713,
+ "cost_for_plan": 0.400440787,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6878,18 +6988,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -6906,28 +7016,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 692.4932617,
+ "cost_for_plan": 0.661998748,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 687.8376465
+ "rows": 27,
+ "cost": 1.576512856
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 692.4932617,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 806.8932617
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.661998748,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.808692068
},
{
- "chosen_strategy": "FirstMatch"
+ "chosen_strategy": "DuplicateWeedout"
}
],
- "pruned_by_cost": true,
- "current_cost": 687.8376465,
- "best_cost": 633.8071312
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
}
]
},
@@ -6940,7 +7053,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 464.9531982,
+ "cost_for_plan": 0.446004385,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6950,7 +7063,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 108.8653809,
+ "cost_for_plan": 0.114053628,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6971,18 +7084,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -6997,18 +7110,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -7024,11 +7137,81 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 877.5730713,
+ "cost_for_plan": 0.742727079,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 877.5730713,
- "best_cost": 633.8071312
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4",
+ "t_inner_2"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 2187
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 6.764540577,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 6.764540577,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4",
+ "t_inner_2"
+ ],
+ "table": "t_inner_3",
+ "rows_for_plan": 19683,
+ "cost_for_plan": 7.507267656,
+ "semijoin_strategy_choice": [
+ {
+ "strategy": "DuplicateWeedout",
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 729,
+ "rows": 27,
+ "dups_cost": 7.507267656,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 3.16837251,
+ "total_cost": 10.70498636
+ },
+ {
+ "chosen_strategy": "DuplicateWeedout"
+ }
+ ],
+ "sj_rows_out": 0.012345679,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 0.137174211,
+ "pruned_by_cost": true,
+ "current_cost": 10.70498636,
+ "best_cost": 0.808692068
+ }
+ ]
},
{
"plan_prefix": [
@@ -7039,11 +7222,9 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 877.5730713,
+ "cost_for_plan": 0.742727079,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 877.5730713,
- "best_cost": 633.8071312
+ "pruned_by_heuristic": true
}
]
},
@@ -7051,7 +7232,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 262.2455078,
+ "cost_for_plan": 0.219286686,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": "min_read_time"
}
@@ -7061,25 +7242,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 3,
- "cost": 36.32946777
+ "rows": 3,
+ "cost": 0.145008465
},
{
"strategy": "DuplicateWeedout",
- "records": 3,
- "dups_cost": 31.17531738,
- "write_cost": 1.45,
- "full_lookup_cost": 12.15,
- "total_cost": 44.77531738
+ "prefix_row_count": 3,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 3,
+ "dups_cost": 0.046471353,
+ "write_cost": 0.02548291,
+ "full_lookup_cost": 0.01303857,
+ "total_cost": 0.084992833
},
{
- "chosen_strategy": "FirstMatch"
+ "chosen_strategy": "DuplicateWeedout"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 3,
+ "sj_filtered": 3.703703704,
"rest_of_plan": [
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
@@ -7094,18 +7281,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 11.69519043,
+ "rows_out": 9,
+ "cost": 0.017419989,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 11.69519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.017419989,
"uses_join_buffering": true
}
}
@@ -7120,18 +7307,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 4.565063477,
+ "rows_out": 3,
+ "cost": 0.012618795,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 4.565063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.012618795,
"uses_join_buffering": true
}
}
@@ -7146,18 +7333,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 11.69519043,
+ "rows_out": 9,
+ "cost": 0.017419989,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 11.69519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.017419989,
"uses_join_buffering": true
}
}
@@ -7168,7 +7355,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 48.0246582,
+ "cost_for_plan": 0.102412822,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7189,18 +7376,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 30.10256348,
+ "rows_out": 3,
+ "cost": 0.034460781,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 30.10256348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.034460781,
"uses_join_buffering": true
}
}
@@ -7215,18 +7402,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 88.30769043,
+ "rows_out": 9,
+ "cost": 0.080024379,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 88.30769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.080024379,
"uses_join_buffering": true
}
}
@@ -7242,7 +7429,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 78.12722168,
+ "cost_for_plan": 0.136873603,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7264,18 +7451,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -7292,25 +7479,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 363.8724121,
+ "cost_for_plan": 0.398431564,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 359.2167969
+ "rows": 27,
+ "cost": 1.312945672
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 363.8724121,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 478.2724121
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.398431564,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.545124884
},
{
- "chosen_strategy": "FirstMatch"
+ "chosen_strategy": "DuplicateWeedout"
}
- ]
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
}
]
},
@@ -7323,7 +7516,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 136.3323486,
+ "cost_for_plan": 0.182437201,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7333,7 +7526,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 40.89453125,
+ "cost_for_plan": 0.097611628,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7354,18 +7547,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 31.60769043,
+ "rows_out": 9,
+ "cost": 0.034303623,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 31.60769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.034303623,
"uses_join_buffering": true
}
}
@@ -7380,18 +7573,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 31.60769043,
+ "rows_out": 9,
+ "cost": 0.034303623,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 31.60769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.034303623,
"uses_join_buffering": true
}
}
@@ -7407,7 +7600,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 72.50222168,
+ "cost_for_plan": 0.131915251,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7429,18 +7622,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -7457,23 +7650,26 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 358.2474121,
+ "cost_for_plan": 0.393473212,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 358.2474121,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 472.6474121
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.393473212,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.540166532
},
{
"chosen_strategy": "DuplicateWeedout"
}
],
- "pruned_by_cost": true,
- "current_cost": 472.6474121,
- "best_cost": 359.2168969
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
}
]
},
@@ -7486,7 +7682,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 72.50222168,
+ "cost_for_plan": 0.131915251,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7496,7 +7692,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 48.0246582,
+ "cost_for_plan": 0.102412822,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7506,7 +7702,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 27,
- "cost_for_plan": 14.82019043,
+ "cost_for_plan": 0.037231395,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7522,18 +7718,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -7548,18 +7744,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -7574,18 +7770,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -7596,7 +7792,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_outer_2",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7617,18 +7813,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -7643,18 +7839,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 768.7076904,
+ "rows_out": 9,
+ "cost": 0.628673451,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 768.7076904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
"uses_join_buffering": true
}
}
@@ -7670,11 +7866,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 862.7230713,
+ "cost_for_plan": 0.731138787,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 862.7230713,
- "best_cost": 359.2168969
+ "current_cost": 0.731138787,
+ "best_cost": 0.540166532
},
{
"plan_prefix": [
@@ -7685,11 +7881,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 862.7230713,
+ "cost_for_plan": 0.731138787,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 862.7230713,
- "best_cost": 359.2168969
+ "current_cost": 0.731138787,
+ "best_cost": 0.540166532
}
]
},
@@ -7697,7 +7893,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7705,7 +7901,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7715,7 +7911,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7725,7 +7921,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7733,7 +7929,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7741,7 +7937,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7751,7 +7947,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_2",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7759,7 +7955,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7767,7 +7963,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7775,7 +7971,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7783,7 +7979,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7792,122 +7988,10 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"fix_semijoin_strategies_for_picked_join_order": [
{
- "semi_join_strategy": "FirstMatch",
- "join_order": [
- {
- "table": "t_inner_4",
- "best_access_path": {
- "table": "t_inner_4",
- "plan_details": {
- "record_count": 27
- },
- "considered_access_paths": [
- {
- "access_type": "scan",
- "rows": 3,
- "rows_after_scan": 3,
- "rows_after_filter": 3,
- "cost": 47.31921387,
- "index_only": false,
- "chosen": true
- }
- ],
- "chosen_access_method": {
- "type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 47.31921387,
- "uses_join_buffering": false
- }
- }
- },
- {
- "table": "t_inner_3",
- "best_access_path": {
- "table": "t_inner_3",
- "plan_details": {
- "record_count": 81
- },
- "considered_access_paths": [
- {
- "access_type": "scan",
- "rows": 9,
- "rows_after_scan": 9,
- "rows_after_filter": 9,
- "cost": 263.8729248,
- "index_only": false,
- "chosen": true
- }
- ],
- "chosen_access_method": {
- "type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 263.8729248,
- "uses_join_buffering": false
- }
- }
- }
- ]
+ "semi_join_strategy": "DuplicateWeedout"
},
{
- "semi_join_strategy": "FirstMatch",
- "join_order": [
- {
- "table": "t_inner_1",
- "best_access_path": {
- "table": "t_inner_1",
- "plan_details": {
- "record_count": 3
- },
- "considered_access_paths": [
- {
- "access_type": "scan",
- "rows": 3,
- "rows_after_scan": 3,
- "rows_after_filter": 3,
- "cost": 5.25769043,
- "index_only": false,
- "chosen": true
- }
- ],
- "chosen_access_method": {
- "type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 5.25769043,
- "uses_join_buffering": false
- }
- }
- },
- {
- "table": "t_inner_2",
- "best_access_path": {
- "table": "t_inner_2",
- "plan_details": {
- "record_count": 9
- },
- "considered_access_paths": [
- {
- "access_type": "scan",
- "rows": 9,
- "rows_after_scan": 9,
- "rows_after_filter": 9,
- "cost": 29.31921387,
- "index_only": false,
- "chosen": true
- }
- ],
- "chosen_access_method": {
- "type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 29.31921387,
- "uses_join_buffering": false
- }
- }
- }
- ]
+ "semi_join_strategy": "DuplicateWeedout"
}
]
},
@@ -7916,12 +8000,12 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"t_outer_1",
"t_inner_1",
"t_inner_2",
- "t_outer_2",
"t_inner_4",
+ "t_outer_2",
"t_inner_3"
],
"rows": 27,
- "cost": 359.2167969
+ "cost": 0.540166532
},
{
"substitute_best_equal": {
@@ -7946,11 +8030,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"attached": null
},
{
- "table": "t_outer_2",
+ "table": "t_inner_4",
"attached": null
},
{
- "table": "t_inner_4",
+ "table": "t_outer_2",
"attached": null
},
{
@@ -7976,8 +8060,8 @@ explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_
t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3
-1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join)
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join)
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t_inner_1 ALL NULL NULL NULL NULL 3
2 MATERIALIZED t_inner_2 ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join)
@@ -8141,48 +8225,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"table": "t_outer_1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_outer_2",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
"table": "t_inner_3",
"table_scan": {
"rows": 9,
- "read_cost": 1.00769043,
- "read_and_compare_cost": 3.25769043
+ "read_cost": 0.011155245,
+ "read_and_compare_cost": 0.011443245
}
},
{
"table": "t_inner_4",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -8215,18 +8299,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -8241,18 +8325,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -8263,7 +8347,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_1"],
@@ -8278,18 +8362,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -8300,7 +8384,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391
+ "cost_for_plan": 0.02463804
}
]
},
@@ -8308,7 +8392,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"pruned_by_heuristic": true
}
]
@@ -8328,18 +8412,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -8354,18 +8438,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -8376,7 +8460,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_4"],
@@ -8391,18 +8475,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -8413,7 +8497,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_inner_4"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391
+ "cost_for_plan": 0.02463804
}
]
},
@@ -8421,7 +8505,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"pruned_by_heuristic": true
}
]
@@ -8444,18 +8528,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -8470,18 +8554,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -8496,18 +8580,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -8522,18 +8606,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -8548,18 +8632,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -8574,18 +8658,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 3.25769043,
+ "rows_out": 9,
+ "cost": 0.011443245,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 3.25769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.011443245,
"uses_join_buffering": false
}
}
@@ -8596,7 +8680,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8612,18 +8696,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -8638,18 +8722,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -8664,18 +8748,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -8690,18 +8774,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 3.890063477,
+ "rows_out": 3,
+ "cost": 0.011523207,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 3.890063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.011523207,
"uses_join_buffering": true
}
}
@@ -8716,18 +8800,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 9.67019043,
+ "rows_out": 9,
+ "cost": 0.014133225,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 9.67019043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.014133225,
"uses_join_buffering": true
}
}
@@ -8738,7 +8822,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8754,18 +8838,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 70.08269043,
+ "rows_out": 9,
+ "cost": 0.050443503,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 70.08269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.050443503,
"uses_join_buffering": true
}
}
@@ -8780,18 +8864,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 24.02756348,
+ "rows_out": 3,
+ "cost": 0.024600489,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 24.02756348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.024600489,
"uses_join_buffering": true
}
}
@@ -8806,18 +8890,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 24.02756348,
+ "rows_out": 3,
+ "cost": 0.024600489,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 24.02756348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.024600489,
"uses_join_buffering": true
}
}
@@ -8832,18 +8916,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 70.08269043,
+ "rows_out": 9,
+ "cost": 0.050443503,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 70.08269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.050443503,
"uses_join_buffering": true
}
}
@@ -8854,7 +8938,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_1",
"rows_for_plan": 81,
- "cost_for_plan": 35.45031738,
+ "cost_for_plan": 0.049238529,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8870,18 +8954,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -8896,18 +8980,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 77.69006348,
+ "rows_out": 3,
+ "cost": 0.067582275,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 77.69006348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.067582275,
"uses_join_buffering": true
}
}
@@ -8922,18 +9006,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -8944,30 +9028,36 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 266.5205078,
+ "cost_for_plan": 0.222053862,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 322.6148926
+ "rows": 27,
+ "cost": 1.23517089
},
{
"strategy": "SJ-Materialization",
- "records": 27,
- "cost": 35.99550781
+ "rows": 27,
+ "cost": 0.083958496
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 266.5205078,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 380.9205078
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.222053862,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.368747182
},
{
"chosen_strategy": "SJ-Materialization"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
"rest_of_plan": [
{
"plan_prefix": [
@@ -8987,18 +9077,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 30.10256348,
+ "rows_out": 3,
+ "cost": 0.034460781,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 30.10256348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.034460781,
"uses_join_buffering": true
}
}
@@ -9013,18 +9103,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 88.30769043,
+ "rows_out": 9,
+ "cost": 0.080024379,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 88.30769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.080024379,
"uses_join_buffering": true
}
}
@@ -9040,7 +9130,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 66.09807129,
+ "cost_for_plan": 0.118419277,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9062,18 +9152,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -9090,30 +9180,36 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 351.8432617,
+ "cost_for_plan": 0.379977238,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 27,
- "cost": 347.1876465
+ "rows": 27,
+ "cost": 1.294491346
},
{
"strategy": "SJ-Materialization",
- "records": 27,
- "cost": 60.56826172
+ "rows": 27,
+ "cost": 0.143278952
},
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 351.8432617,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 466.2432617
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.379977238,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.526670558
},
{
"chosen_strategy": "SJ-Materialization"
}
- ]
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
}
]
},
@@ -9126,11 +9222,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 124.3031982,
+ "cost_for_plan": 0.163982875,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 124.3031982,
- "best_cost": 60.56836172
+ "current_cost": 0.163982875,
+ "best_cost": 0.143278952
}
]
},
@@ -9138,21 +9234,19 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 113.1403809,
+ "cost_for_plan": 0.116820804,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 113.1403809,
- "best_cost": 60.56836172
+ "pruned_by_heuristic": true
},
{
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 266.5205078,
+ "cost_for_plan": 0.222053862,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 266.5205078,
- "best_cost": 60.56836172
+ "current_cost": 0.222053862,
+ "best_cost": 0.143278952
}
]
},
@@ -9160,17 +9254,15 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 81.50544434,
+ "cost_for_plan": 0.075081543,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 81.50544434,
- "best_cost": 60.56836172
+ "pruned_by_heuristic": true
},
{
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 35.45031738,
+ "cost_for_plan": 0.049238529,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -9178,11 +9270,9 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 81.50544434,
+ "cost_for_plan": 0.075081543,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 81.50544434,
- "best_cost": 60.56836172
+ "pruned_by_heuristic": true
}
]
},
@@ -9190,7 +9280,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9206,18 +9296,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -9232,18 +9322,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -9258,18 +9348,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 9.177563477,
+ "rows_out": 3,
+ "cost": 0.015203373,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 9.177563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.015203373,
"uses_join_buffering": true
}
}
@@ -9284,18 +9374,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 25.53269043,
+ "rows_out": 9,
+ "cost": 0.024443331,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 25.53269043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.024443331,
"uses_join_buffering": true
}
}
@@ -9306,7 +9396,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9322,18 +9412,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -9348,18 +9438,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 77.69006348,
+ "rows_out": 3,
+ "cost": 0.067582275,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 77.69006348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.067582275,
"uses_join_buffering": true
}
}
@@ -9374,18 +9464,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 231.0701904,
+ "rows_out": 9,
+ "cost": 0.172815333,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 231.0701904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.172815333,
"uses_join_buffering": true
}
}
@@ -9396,43 +9486,222 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 262.2455078,
+ "cost_for_plan": 0.219286686,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 262.2455078,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 376.6455078
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.219286686,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.365980006
},
{
"chosen_strategy": "DuplicateWeedout"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
"pruned_by_cost": true,
- "current_cost": 376.6455078,
- "best_cost": 60.56836172
+ "current_cost": 0.365980006,
+ "best_cost": 0.143278952
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 108.8653809,
+ "cost_for_plan": 0.114053628,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 108.8653809,
- "best_cost": 60.56836172
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_2",
+ "plan_details": {
+ "record_count": 243
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "uses_join_buffering": true
+ }
+ }
+ },
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 243
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4"
+ ],
+ "table": "t_inner_2",
+ "rows_for_plan": 2187,
+ "cost_for_plan": 0.742727079,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 0.742727079,
+ "best_cost": 0.143278952
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4"
+ ],
+ "table": "t_inner_3",
+ "rows_for_plan": 2187,
+ "cost_for_plan": 0.742727079,
+ "semijoin_strategy_choice": [
+ {
+ "strategy": "SJ-Materialization",
+ "rows": 81,
+ "cost": 0.116338225
+ },
+ {
+ "chosen_strategy": "SJ-Materialization"
+ }
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 81,
+ "sj_filtered": 3.703703704,
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4",
+ "t_inner_3"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_2",
+ "plan_details": {
+ "record_count": 81
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_outer_2",
+ "t_inner_4",
+ "t_inner_3"
+ ],
+ "table": "t_inner_2",
+ "rows_for_plan": 729,
+ "cost_for_plan": 0.377896186,
+ "semijoin_strategy_choice": [
+ {
+ "strategy": "DuplicateWeedout",
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 1.00428504,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 1.15097836
+ },
+ {
+ "chosen_strategy": "DuplicateWeedout"
+ }
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
+ "pruned_by_cost": true,
+ "current_cost": 1.15097836,
+ "best_cost": 0.143278952
+ }
+ ]
+ }
+ ]
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 262.2455078,
+ "cost_for_plan": 0.219286686,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 262.2455078,
- "best_cost": 60.56836172
+ "current_cost": 0.219286686,
+ "best_cost": 0.143278952
}
]
},
@@ -9440,30 +9709,36 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
- "records": 3,
- "cost": 36.32946777
+ "rows": 3,
+ "cost": 0.145008465
},
{
"strategy": "SJ-Materialization",
- "records": 3,
- "cost": 19.12531738
+ "rows": 3,
+ "cost": 0.065137975
},
{
"strategy": "DuplicateWeedout",
- "records": 3,
- "dups_cost": 31.17531738,
- "write_cost": 1.45,
- "full_lookup_cost": 12.15,
- "total_cost": 44.77531738
+ "prefix_row_count": 3,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 3,
+ "dups_cost": 0.046471353,
+ "write_cost": 0.02548291,
+ "full_lookup_cost": 0.01303857,
+ "total_cost": 0.084992833
},
{
"chosen_strategy": "SJ-Materialization"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 3,
+ "sj_filtered": 3.703703704,
"rest_of_plan": [
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
@@ -9478,18 +9753,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 11.69519043,
+ "rows_out": 9,
+ "cost": 0.017419989,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 11.69519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.017419989,
"uses_join_buffering": true
}
}
@@ -9504,18 +9779,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 4.565063477,
+ "rows_out": 3,
+ "cost": 0.012618795,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 4.565063477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.012618795,
"uses_join_buffering": true
}
}
@@ -9530,18 +9805,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 11.69519043,
+ "rows_out": 9,
+ "cost": 0.017419989,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 11.69519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.017419989,
"uses_join_buffering": true
}
}
@@ -9552,7 +9827,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 30.82050781,
+ "cost_for_plan": 0.082557964,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9573,18 +9848,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 30.10256348,
+ "rows_out": 3,
+ "cost": 0.034460781,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 30.10256348,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.034460781,
"uses_join_buffering": true
}
}
@@ -9599,18 +9874,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 88.30769043,
+ "rows_out": 9,
+ "cost": 0.080024379,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 88.30769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.080024379,
"uses_join_buffering": true
}
}
@@ -9626,11 +9901,88 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 60.92307129,
+ "cost_for_plan": 0.117018745,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 60.92307129,
- "best_cost": 60.56836172
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_inner_2",
+ "t_outer_2",
+ "t_inner_4"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_inner_2",
+ "t_outer_2",
+ "t_inner_4"
+ ],
+ "table": "t_inner_3",
+ "rows_for_plan": 729,
+ "cost_for_plan": 0.378576706,
+ "semijoin_strategy_choice": [
+ {
+ "strategy": "FirstMatch",
+ "rows": 27,
+ "cost": 1.293090814
+ },
+ {
+ "strategy": "SJ-Materialization",
+ "rows": 27,
+ "cost": 0.14187842
+ },
+ {
+ "strategy": "DuplicateWeedout",
+ "prefix_row_count": 27,
+ "tmp_table_rows": 1,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.378576706,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.525270026
+ },
+ {
+ "chosen_strategy": "SJ-Materialization"
+ }
+ ],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704
+ }
+ ]
},
{
"plan_prefix": [
@@ -9641,11 +9993,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 119.1281982,
+ "cost_for_plan": 0.162582343,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 119.1281982,
- "best_cost": 60.56836172
+ "current_cost": 0.162582343,
+ "best_cost": 0.14187842
}
]
},
@@ -9653,7 +10005,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 23.69038086,
+ "cost_for_plan": 0.07775677,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9674,18 +10026,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 31.60769043,
+ "rows_out": 9,
+ "cost": 0.034303623,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 31.60769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.034303623,
"uses_join_buffering": true
}
}
@@ -9700,18 +10052,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 31.60769043,
+ "rows_out": 9,
+ "cost": 0.034303623,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 31.60769043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.034303623,
"uses_join_buffering": true
}
}
@@ -9727,7 +10079,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 55.29807129,
+ "cost_for_plan": 0.112060393,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9749,18 +10101,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 285.7451904,
+ "rows_out": 9,
+ "cost": 0.261557961,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 285.7451904,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.261557961,
"uses_join_buffering": true
}
}
@@ -9777,23 +10129,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 341.0432617,
+ "cost_for_plan": 0.373618354,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
- "records": 27,
- "dups_cost": 341.0432617,
- "write_cost": 5.05,
- "full_lookup_cost": 109.35,
- "total_cost": 455.4432617
+ "prefix_row_count": 3,
+ "tmp_table_rows": 9,
+ "sj_inner_fanout": 27,
+ "rows": 27,
+ "dups_cost": 0.373618354,
+ "write_cost": 0.02934619,
+ "full_lookup_cost": 0.11734713,
+ "total_cost": 0.520311674
},
{
"chosen_strategy": "DuplicateWeedout"
}
],
+ "sj_rows_out": 0.333333333,
+ "sj_rows_for_plan": 27,
+ "sj_filtered": 3.703703704,
"pruned_by_cost": true,
- "current_cost": 455.4432617,
- "best_cost": 60.56836172
+ "current_cost": 0.520311674,
+ "best_cost": 0.14187842
}
]
},
@@ -9806,7 +10164,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 55.29807129,
+ "cost_for_plan": 0.112060393,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -9816,7 +10174,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 30.82050781,
+ "cost_for_plan": 0.082557964,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -9826,7 +10184,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 27,
- "cost_for_plan": 14.82019043,
+ "cost_for_plan": 0.037231395,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -9842,18 +10200,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -9868,18 +10226,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -9894,18 +10252,18 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"access_type": "scan_with_join_cache",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 9,
- "cost": 79.19519043,
+ "rows_out": 9,
+ "cost": 0.065233941,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 9,
- "records_out": 9,
- "cost": 79.19519043,
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.065233941,
"uses_join_buffering": true
}
}
@@ -9916,31 +10274,118 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_outer_2",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 94.01538086,
- "best_cost": 60.56836172
+ "rest_of_plan": [
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_inner_4",
+ "t_outer_2"
+ ],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_inner_2",
+ "plan_details": {
+ "record_count": 243
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "uses_join_buffering": true
+ }
+ }
+ },
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 243
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_filter": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "rows_read": 9,
+ "rows_out": 9,
+ "cost": 0.628673451,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_inner_4",
+ "t_outer_2"
+ ],
+ "table": "t_inner_2",
+ "rows_for_plan": 2187,
+ "cost_for_plan": 0.731138787,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 0.731138787,
+ "best_cost": 0.14187842
+ },
+ {
+ "plan_prefix": [
+ "t_outer_1",
+ "t_inner_1",
+ "t_inner_4",
+ "t_outer_2"
+ ],
+ "table": "t_inner_3",
+ "rows_for_plan": 2187,
+ "cost_for_plan": 0.731138787,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 0.731138787,
+ "best_cost": 0.14187842
+ }
+ ]
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 94.01538086,
- "best_cost": 60.56836172
+ "pruned_by_heuristic": true
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 94.01538086,
+ "cost_for_plan": 0.102465336,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 94.01538086,
- "best_cost": 60.56836172
+ "pruned_by_heuristic": true
}
]
},
@@ -9948,7 +10393,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 31.17531738,
+ "cost_for_plan": 0.046471353,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -9958,7 +10403,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -9966,7 +10411,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 5.642626953,
+ "cost_for_plan": 0.022028022,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -9974,7 +10419,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 11.42275391,
+ "cost_for_plan": 0.02463804,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -9984,7 +10429,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_2",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -9992,7 +10437,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -10000,7 +10445,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -10008,7 +10453,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -10016,7 +10461,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 3.25769043,
+ "cost_for_plan": 0.011443245,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -10051,12 +10496,12 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_join_order": [
"t_outer_1",
- "t_outer_2",
"<subquery2>",
+ "t_outer_2",
"<subquery3>"
],
"rows": 27,
- "cost": 60.56826172
+ "cost": 0.14187842
},
{
"substitute_best_equal": {
@@ -10077,10 +10522,6 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"attached": null
},
{
- "table": "t_outer_2",
- "attached": null
- },
- {
"table": "t_inner_1",
"attached": null
},
@@ -10093,6 +10534,10 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"attached": null
},
{
+ "table": "t_outer_2",
+ "attached": null
+ },
+ {
"table": "t_inner_4",
"attached": null
},
@@ -10160,7 +10605,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.745829876,
+ "cost": 0.001388369,
"chosen": true
}
],
@@ -10189,7 +10634,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 107,
- "cost": 24.68379668,
+ "cost": 0.016044989,
"chosen": true
}
],
@@ -10221,7 +10666,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 756.2522431,
+ "cost": 1.235599899,
"chosen": true
}
],
@@ -10261,7 +10706,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 4,
- "cost": 3.523710032,
+ "cost": 0.006185575,
"chosen": true
}
],
@@ -10295,7 +10740,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.271171589,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10324,7 +10769,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.271171589,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10361,7 +10806,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270927508,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10391,7 +10836,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270878692,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10421,7 +10866,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270927508,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10454,7 +10899,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270878692,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10490,7 +10935,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.319255553,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10509,7 +10954,7 @@ INSERT INTO t1 VALUES (2, 'ab\n');
set optimizer_trace=1;
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL i_b NULL NULL NULL 2 Using where
+1 SIMPLE t1 ref i_b i_b 13 const 2 Using index condition
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
@@ -10524,9 +10969,8 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2,
- "cost": 2.021855016,
- "chosen": false,
- "cause": "cost"
+ "cost": 0.003717837,
+ "chosen": true
}
],
"analyzing_roworder_intersect":
@@ -10580,7 +11024,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 756.2522431,
+ "cost": 1.235599899,
"chosen": true
}
],
@@ -10647,9 +11091,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 5,
"rows_after_filter": 5,
- "cost": 3.508544922,
+ "rows_out": 5,
+ "cost": 0.01159965,
"index_only": false,
"chosen": true
}
@@ -10657,9 +11101,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 5,
- "records_out": 5,
- "cost": 3.508544922,
+ "rows_read": 5,
+ "rows_out": 5,
+ "cost": 0.01159965,
"uses_join_buffering": false
}
}
@@ -10677,9 +11121,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 1000,
- "rows_after_scan": 800,
"rows_after_filter": 800,
- "cost": 252.0986328,
+ "rows_out": 800,
+ "cost": 0.1669214,
"index_only": false,
"chosen": true
}
@@ -10687,9 +11131,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 800,
- "records_out": 800,
- "cost": 252.0986328,
+ "rows_read": 800,
+ "rows_out": 800,
+ "cost": 0.1669214,
"uses_join_buffering": false
}
}
@@ -10701,7 +11145,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "A",
"rows_for_plan": 5,
- "cost_for_plan": 3.508544922,
+ "cost_for_plan": 0.01159965,
"rest_of_plan":
[
{
@@ -10722,9 +11166,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 1000,
- "rows_after_scan": 800,
"rows_after_filter": 800,
- "cost": 1260.493164,
+ "rows_out": 800,
+ "cost": 0.834607,
"index_only": false,
"chosen": true
}
@@ -10732,9 +11176,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 800,
- "records_out": 800,
- "cost": 1260.493164,
+ "rows_read": 800,
+ "rows_out": 800,
+ "cost": 0.834607,
"uses_join_buffering": false
}
}
@@ -10746,7 +11190,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["A"],
"table": "B",
"rows_for_plan": 4000,
- "cost_for_plan": 1264.001709
+ "cost_for_plan": 0.84620665
}
]
},
@@ -10755,7 +11199,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "B",
"rows_for_plan": 800,
- "cost_for_plan": 252.0986328,
+ "cost_for_plan": 0.1669214,
"pruned_by_heuristic": true
}
]
@@ -10788,9 +11232,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 10,
"rows_after_filter": 10,
- "cost": 3.508544922,
+ "rows_out": 10,
+ "cost": 0.01159965,
"index_only": false,
"chosen": true
}
@@ -10798,9 +11242,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.508544922,
+ "rows_read": 10,
+ "rows_out": 10,
+ "cost": 0.01159965,
"uses_join_buffering": false
}
}
@@ -10818,9 +11262,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 1000,
- "rows_after_scan": 800,
"rows_after_filter": 800,
- "cost": 252.0986328,
+ "rows_out": 800,
+ "cost": 0.1669214,
"index_only": false,
"chosen": true
}
@@ -10828,9 +11272,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 800,
- "records_out": 800,
- "cost": 252.0986328,
+ "rows_read": 800,
+ "rows_out": 800,
+ "cost": 0.1669214,
"uses_join_buffering": false
}
}
@@ -10842,7 +11286,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "A",
"rows_for_plan": 10,
- "cost_for_plan": 3.508544922,
+ "cost_for_plan": 0.01159965,
"rest_of_plan":
[
{
@@ -10866,25 +11310,21 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cost": 12.50585794,
+ "cost": 0.01810946,
"chosen": true
},
{
- "access_type": "scan_with_join_cache",
- "rows": 1000,
- "rows_after_scan": 600,
- "rows_after_filter": 600,
- "cost": 1677.098633,
- "index_only": false,
- "chosen": false
+ "type": "scan",
+ "chosen": false,
+ "cause": "cost"
}
],
"chosen_access_method":
{
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 12.50585794,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.01810946,
"uses_join_buffering": false
}
}
@@ -10896,7 +11336,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["A"],
"table": "B",
"rows_for_plan": 10,
- "cost_for_plan": 16.01440287,
+ "cost_for_plan": 0.02970911,
+ "pushdown_cond_selectivity": 0.8,
+ "filtered": 80,
+ "rows_out": 0.8,
"selectivity": 0.8,
"estimated_join_cardinality": 8
}
@@ -10907,10 +11350,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "B",
"rows_for_plan": 800,
- "cost_for_plan": 252.0986328,
+ "cost_for_plan": 0.1669214,
"pruned_by_cost": true,
- "current_cost": 252.0986328,
- "best_cost": 16.01450287
+ "current_cost": 0.1669214,
+ "best_cost": 0.02970911
}
]
]
@@ -10939,7 +11382,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.282887479,
+ "cost": 0.002483968,
"chosen": true
}
],
@@ -10964,9 +11407,9 @@ insert into t3 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
explain
select * from t3 where (a,a) in (select t1.a, t2.a from t1, t2 where t1.b=t2.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5
-1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
-1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using where
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout'))
[
@@ -10999,7 +11442,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.745829876,
+ "cost": 0.001388369,
"chosen": true
}
]
@@ -11039,9 +11482,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 10,
- "rows_after_scan": 10,
"rows_after_filter": 10,
- "cost": 3.510986328,
+ "rows_out": 10,
+ "cost": 0.01159965,
"index_only": false,
"chosen": true
}
@@ -11049,9 +11492,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 10,
- "records_out": 10,
- "cost": 3.510986328,
+ "rows_read": 10,
+ "rows_out": 10,
+ "cost": 0.01159965,
"uses_join_buffering": false
}
}
@@ -11069,9 +11512,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"access_type": "scan",
"rows": 100,
- "rows_after_scan": 100,
"rows_after_filter": 100,
- "cost": 26.10986328,
+ "rows_out": 100,
+ "cost": 0.0256761,
"index_only": false,
"chosen": true,
"use_tmp_table": true
@@ -11080,9 +11523,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "scan",
- "records_read": 100,
- "records_out": 100,
- "cost": 26.10986328,
+ "rows_read": 100,
+ "rows_out": 100,
+ "cost": 0.0256761,
"uses_join_buffering": false
}
}
@@ -11094,7 +11537,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t1",
"rows_for_plan": 10,
- "cost_for_plan": 3.510986328,
+ "cost_for_plan": 0.01159965,
"rest_of_plan":
[
{
@@ -11118,25 +11561,21 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cost": 12.50585794,
+ "cost": 0.01749506,
"chosen": true
},
{
- "access_type": "scan_with_join_cache",
- "rows": 100,
- "rows_after_scan": 75,
- "rows_after_filter": 75,
- "cost": 204.2348633,
- "index_only": false,
- "chosen": false
+ "type": "scan",
+ "chosen": false,
+ "cause": "cost"
}
],
"chosen_access_method":
{
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 12.50585794,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.01749506,
"uses_join_buffering": false
}
}
@@ -11148,8 +11587,8 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["t1"],
"table": "t2",
"rows_for_plan": 10,
- "cost_for_plan": 16.01684427,
- "cost_for_sorting": 10
+ "cost_for_plan": 0.02909471,
+ "cost_for_sorting": 0.006368384
}
]
},
@@ -11158,10 +11597,75 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 26.10986328,
- "pruned_by_cost": true,
- "current_cost": 26.10986328,
- "best_cost": 26.01694427
+ "cost_for_plan": 0.0256761,
+ "rest_of_plan":
+ [
+
+ {
+ "plan_prefix":
+ [
+ "t2"
+ ],
+ "get_costs_for_tables":
+ [
+
+ {
+ "best_access_path":
+ {
+ "table": "t1",
+ "plan_details":
+ {
+ "record_count": 100
+ },
+ "considered_access_paths":
+ [
+
+ {
+ "access_type": "ref",
+ "index": "a",
+ "used_range_estimates": false,
+ "reason": "not available",
+ "rows": 1,
+ "cost": 0.1731074,
+ "chosen": true
+ },
+
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 10,
+ "rows_after_filter": 10,
+ "rows_out": 1,
+ "cost": 0.11055225,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method":
+ {
+ "type": "scan",
+ "rows_read": 10,
+ "rows_out": 1,
+ "cost": 0.11055225,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+
+ {
+ "plan_prefix":
+ [
+ "t2"
+ ],
+ "table": "t1",
+ "rows_for_plan": 100,
+ "cost_for_plan": 0.13622835,
+ "pruned_by_cost": true,
+ "current_cost": 0.13622835,
+ "best_cost": 0.035463094
+ }
+ ]
}
]
]
@@ -11179,7 +11683,7 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN EXTENDED SELECT * from t1 WHERE a between 1 and 5 and b <= 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 100 1.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 100 0.25 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`a` between 1 and 5 and `test`.`t1`.`b` <= 5
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
@@ -11259,7 +11763,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 0,
- "cost": 0.52,
+ "cost": 0.001340684,
"chosen": true
}
]
@@ -11361,8 +11865,8 @@ select count(*) from seq_1_to_10000000 {
"table": "seq_1_to_10000000",
"table_scan": {
"rows": 10000000,
- "read_cost": 5000000,
- "read_and_compare_cost": 7250000
+ "read_cost": 124.7880673,
+ "read_and_compare_cost": 444.7880673
}
}
]
@@ -11382,18 +11886,18 @@ select count(*) from seq_1_to_10000000 {
{
"access_type": "scan",
"rows": 10000000,
- "rows_after_scan": 10000000,
"rows_after_filter": 10000000,
- "cost": 7250000,
+ "rows_out": 10000000,
+ "cost": 444.7880673,
"index_only": true,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 10000000,
- "records_out": 10000000,
- "cost": 7250000,
+ "rows_read": 10000000,
+ "rows_out": 10000000,
+ "cost": 444.7880673,
"uses_join_buffering": false
}
}
@@ -11404,14 +11908,14 @@ select count(*) from seq_1_to_10000000 {
"plan_prefix": [],
"table": "seq_1_to_10000000",
"rows_for_plan": 10000000,
- "cost_for_plan": 7250000
+ "cost_for_plan": 444.7880673
}
]
},
{
"best_join_order": ["seq_1_to_10000000"],
"rows": 10000000,
- "cost": 7250000
+ "cost": 444.7880673
},
{
"attaching_conditions_to_tables": {
@@ -11450,7 +11954,7 @@ explain
select * from t1 left join (t2 join t3 on t3.pk=1000) on t2.a=t1.a and t2.pk is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY NULL NULL NULL 1 Impossible ON condition
-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 10
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.mark_join_nest_as_const'))
from information_schema.optimizer_trace;
@@ -11771,7 +12275,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1.8367,
- "cost": 1.417925794,
+ "cost": 0.0019606,
"chosen": true
},
{
@@ -11783,9 +12287,9 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
"chosen_access_method":
{
"type": "ref",
- "records_read": 1.8367,
- "records_out": 1.8367,
- "cost": 1.417925794,
+ "rows_read": 1.8367,
+ "rows_out": 1.8367,
+ "cost": 0.0019606,
"uses_join_buffering": false
}
}
@@ -11797,19 +12301,25 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
[],
"table": "t2",
"rows_for_plan": 1.8367,
- "cost_for_plan": 1.417925794,
- "cost_for_sorting": 1.8367
+ "cost_for_plan": 0.0019606,
+ "cost_for_sorting": 0.001155201
}
]
},
{
- "best_splitting":
+ "split_materialized":
{
"table": "t2",
"key": "idx_a",
- "record_count": 4,
- "cost": 4.157170953,
- "unsplit_cost": 60.1794762
+ "org_cost": 0.0019606,
+ "postjoin_cost": 0.001135418,
+ "one_splitting_cost": 0.003096018,
+ "unsplit_postjoin_cost": 0.036032575,
+ "unsplit_cost": 0.060625425,
+ "rows": 1.8367,
+ "outer_rows": 4,
+ "total_splitting_cost": 0.012384072,
+ "chosen": true
}
}
]
@@ -11819,13 +12329,7 @@ json_detailed(json_extract(trace, '$**.lateral_derived'))
from
information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.lateral_derived'))
-[
- {
- "startup_cost": 16.62868381,
- "splitting_cost": 4.157170953,
- "records": 1
- }
-]
+NULL
drop table t1,t2;
#
# Test table functions.
@@ -11881,7 +12385,6 @@ set @save_histogram_size= @@histogram_size;
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set optimizer_switch='rowid_filter=on';
set use_stat_tables='preferably';
-set optimizer_use_condition_selectivity=4;
set histogram_size=127;
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;
@@ -11949,7 +12452,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 252.5869141
+ "cost": 0.1671618
},
"potential_range_indexes": [
{
@@ -11973,7 +12476,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"using_mrr": false,
"index_only": false,
"rows": 9,
- "cost": 7.27527215,
+ "cost": 0.01235492,
"chosen": true
},
{
@@ -11983,7 +12486,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"using_mrr": false,
"index_only": false,
"rows": 21,
- "cost": 16.28230168,
+ "cost": 0.027161348,
"chosen": false,
"cause": "cost"
}
@@ -12005,7 +12508,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"ranges": ["(NULL) < (a) < (10)"]
},
"rows_for_plan": 9,
- "cost_for_plan": 7.27527215,
+ "cost_for_plan": 0.01235492,
"chosen": true
}
}
@@ -12015,12 +12518,12 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"rowid_filters": [
{
"key": "a",
- "build_cost": 0.759047172,
+ "build_cost": 9.95653e-5,
"rows": 9
},
{
"key": "b",
- "build_cost": 1.122236655,
+ "build_cost": 3.004222e-4,
"rows": 21
}
]
@@ -12061,33 +12564,37 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"considered_access_paths": [
{
"filter": {
- "rowid_filter_key": "b",
- "index_only_cost": 0.50527215,
- "filter_startup_cost": 1.122236655,
- "find_key_and_filter_lookup_cost": 0.386507019,
+ "rowid_filter_index": "b",
+ "index_only_cost": 0.001515222,
+ "filter_startup_cost": 3.004222e-4,
+ "find_key_and_filter_lookup_cost": 6.445451e-4,
"filter_selectivity": 0.021,
- "orginal_rows": 9,
+ "original_rows": 9,
"new_rows": 0.189,
- "original_found_rows_cost": 5.45527215,
- "new_found_rows_cost": 1.381168455,
- "cost": 2.54120511,
+ "original_access_cost": 0.011516778,
+ "with_filter_access_cost": 0.0023698,
+ "original_found_rows_cost": 0.010001556,
+ "with_filter_found_rows_cost": 2.100327e-4,
+ "org_cost": 0.011804778,
+ "filter_cost": 0.00267627,
"filter_used": true
},
"access_type": "range",
+ "range_index": "a",
"rows": 9,
- "rows_after_scan": 9,
"rows_after_filter": 0.189,
- "cost": 2.54120511,
+ "rows_out": 0.017766,
+ "cost": 0.00267627,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
- "records_read": 9,
- "records_out": 0.017766,
- "cost": 2.54120511,
+ "rows_read": 0.189,
+ "rows_out": 0.017766,
+ "cost": 0.00267627,
"uses_join_buffering": false,
- "rowid_filter_key": "b"
+ "rowid_filter_index": "b"
}
}
}
@@ -12096,23 +12603,22 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
{
"plan_prefix": [],
"table": "t1",
- "rows_for_plan": 9,
- "cost_for_plan": 2.54120511
+ "rows_for_plan": 0.017766,
+ "cost_for_plan": 0.00267627,
+ "pushdown_cond_selectivity": 0.094,
+ "filtered": 0.1974,
+ "rows_out": 0.017766
}
]
},
{
"best_join_order": ["t1"],
- "rows": 9,
- "cost": 2.54120511
+ "rows": 0.017766,
+ "cost": 0.00267627
},
{
"table": "t1",
"range_analysis": {
- "table_scan": {
- "rows": 1000,
- "cost": 1.79769e308
- },
"potential_range_indexes": [
{
"index": "a",
@@ -12135,7 +12641,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"using_mrr": false,
"index_only": true,
"rows": 21,
- "cost": 5.257301684,
+ "cost": 0.004153769,
"chosen": true
}
]
@@ -12148,7 +12654,7 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"ranges": ["(10) <= (b) <= (50)"]
},
"rows_for_plan": 21,
- "cost_for_plan": 5.257301684,
+ "cost_for_plan": 0.004153769,
"chosen": true
}
}
@@ -12190,6 +12696,7 @@ analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
+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;
EXPLAIN
{
@@ -12223,13 +12730,47 @@ EXPLAIN
"selectivity_pct": 43.12
},
"rows": 1000,
- "filtered": 4.307688236,
+ "filtered": 43.11999893,
"attached_condition": "t1.b < 5000 and t1.c < 1000"
}
}
]
}
}
+set optimizer_use_condition_selectivity=4;
+explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "three",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ },
+ {
+ "block-nl-join": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "possible_keys": ["a", "b"],
+ "rows": 10000,
+ "filtered": 4.307688236,
+ "attached_condition": "t1.b < 5000 and t1.c < 1000"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "65",
+ "join_type": "BNL",
+ "attached_condition": "t1.a = three.a"
+ }
+ }
+ ]
+ }
+}
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000 {
"steps": [
@@ -12300,8 +12841,8 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"table": "three",
"table_scan": {
"rows": 3,
- "read_cost": 1.002563477,
- "read_and_compare_cost": 1.752563477
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
},
{
@@ -12309,7 +12850,7 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"range_analysis": {
"table_scan": {
"rows": 10000,
- "cost": 2516.869141
+ "cost": 1.581538
},
"potential_range_indexes": [
{
@@ -12333,7 +12874,7 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"using_mrr": false,
"index_only": false,
"rows": 4312,
- "cost": 3260.045946,
+ "cost": 5.325058827,
"chosen": false,
"cause": "cost"
}
@@ -12354,7 +12895,7 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"rowid_filters": [
{
"key": "b",
- "build_cost": 174.2257513,
+ "build_cost": 0.149564727,
"rows": 4312
}
]
@@ -12392,18 +12933,18 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
{
"access_type": "scan",
"rows": 3,
- "rows_after_scan": 3,
"rows_after_filter": 3,
- "cost": 1.752563477,
+ "rows_out": 3,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 3,
- "records_out": 3,
- "cost": 1.752563477,
+ "rows_read": 3,
+ "rows_out": 3,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -12418,18 +12959,18 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
{
"access_type": "scan",
"rows": 10000,
- "rows_after_scan": 430.7688,
"rows_after_filter": 430.7688,
- "cost": 2516.869141,
+ "rows_out": 430.7688,
+ "cost": 1.581538,
"index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
- "records_read": 430.7688,
- "records_out": 430.7688,
- "cost": 2516.869141,
+ "rows_read": 430.7688,
+ "rows_out": 430.7688,
+ "cost": 1.581538,
"uses_join_buffering": false
}
}
@@ -12440,7 +12981,7 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"plan_prefix": [],
"table": "three",
"rows_for_plan": 3,
- "cost_for_plan": 1.752563477,
+ "cost_for_plan": 0.010504815,
"rest_of_plan": [
{
"plan_prefix": ["three"],
@@ -12458,39 +12999,41 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"used_range_estimates": false,
"reason": "not available",
"filter": {
- "rowid_filter_key": "b",
- "index_only_cost": 2.585794484,
- "filter_startup_cost": 174.2257513,
- "find_key_and_filter_lookup_cost": 96.19157113,
+ "rowid_filter_index": "b",
+ "index_only_cost": 0.092006157,
+ "filter_startup_cost": 0.149564727,
+ "find_key_and_filter_lookup_cost": 0.085742374,
"filter_selectivity": 0.4312,
- "orginal_rows": 1000,
+ "original_rows": 1000,
"new_rows": 431.2,
- "original_found_rows_cost": 552.5857945,
- "new_found_rows_cost": 335.9373656,
- "cost": 1440.757848,
+ "original_access_cost": 1.203290157,
+ "with_filter_access_cost": 0.656934192,
+ "original_found_rows_cost": 1.111284,
+ "with_filter_found_rows_cost": 0.479185661,
+ "org_cost": 3.705870471,
+ "filter_cost": 2.161762502,
"filter_used": true
},
"rows": 431.2,
- "cost": 1440.757848,
+ "cost": 2.161762502,
"chosen": true
},
{
"access_type": "scan_with_join_cache",
"rows": 10000,
- "rows_after_scan": 323.0766,
- "rows_after_filter": 323.0766,
- "cost": 2747.061218,
+ "rows_after_filter": 430.7688,
+ "rows_out": 430.7688,
+ "cost": 1.701731924,
"index_only": false,
- "chosen": false
+ "chosen": true
}
],
"chosen_access_method": {
- "type": "ref",
- "records_read": 1000,
- "records_out": 323.0766,
- "cost": 1440.757848,
- "uses_join_buffering": false,
- "rowid_filter_key": "b"
+ "type": "scan",
+ "rows_read": 430.7688,
+ "rows_out": 430.7688,
+ "cost": 1.701731924,
+ "uses_join_buffering": true
}
}
}
@@ -12499,10 +13042,8 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
{
"plan_prefix": ["three"],
"table": "t1",
- "rows_for_plan": 3000,
- "cost_for_plan": 1442.510412,
- "selectivity": 0.04307688,
- "estimated_join_cardinality": 129.23064
+ "rows_for_plan": 1292.3064,
+ "cost_for_plan": 1.712236739
}
]
},
@@ -12510,64 +13051,15 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 430.7688,
- "cost_for_plan": 2516.869141,
- "pruned_by_cost": true,
- "current_cost": 2516.869141,
- "best_cost": 1442.510512
+ "cost_for_plan": 1.581538,
+ "pruned_by_heuristic": true
}
]
},
{
"best_join_order": ["three", "t1"],
- "rows": 129.23064,
- "cost": 1442.510412
- },
- {
- "table": "t1",
- "range_analysis": {
- "table_scan": {
- "rows": 10000,
- "cost": 1.79769e308
- },
- "potential_range_indexes": [
- {
- "index": "a",
- "usable": false,
- "cause": "not applicable"
- },
- {
- "index": "b",
- "usable": true,
- "key_parts": ["b"]
- }
- ],
- "setup_range_conditions": [],
- "analyzing_range_alternatives": {
- "range_scan_alternatives": [
- {
- "index": "b",
- "ranges": ["(NULL) < (b) < (5000)"],
- "rowid_ordered": false,
- "using_mrr": false,
- "index_only": true,
- "rows": 4312,
- "cost": 996.2459458,
- "chosen": true
- }
- ]
- },
- "chosen_range_access_summary": {
- "range_access_plan": {
- "type": "range_scan",
- "index": "b",
- "rows": 4312,
- "ranges": ["(NULL) < (b) < (5000)"]
- },
- "rows_for_plan": 4312,
- "cost_for_plan": 996.2459458,
- "chosen": true
- }
- }
+ "rows": 1292.3064,
+ "cost": 1.712236739
},
{
"substitute_best_equal": {
@@ -12577,15 +13069,64 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
},
{
"attaching_conditions_to_tables": {
- "attached_conditions_computation": [],
+ "attached_conditions_computation": [
+ {
+ "table": "t1",
+ "range_analysis": {
+ "table_scan": {
+ "rows": 10000,
+ "cost": 1.581538
+ },
+ "potential_range_indexes": [
+ {
+ "index": "a",
+ "usable": true,
+ "key_parts": ["a"]
+ },
+ {
+ "index": "b",
+ "usable": true,
+ "key_parts": ["b"]
+ }
+ ],
+ "setup_range_conditions": [],
+ "analyzing_range_alternatives": {
+ "range_scan_alternatives": [
+ {
+ "index": "a"
+ },
+ {
+ "index": "b",
+ "ranges": ["(NULL) < (b) < (5000)"],
+ "rowid_ordered": false,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 4312,
+ "cost": 5.325058827,
+ "chosen": false,
+ "cause": "cost"
+ }
+ ],
+ "analyzing_roworder_intersect": {
+ "cause": "too few roworder scans"
+ },
+ "analyzing_index_merge_union": []
+ },
+ "group_index_range": {
+ "chosen": false,
+ "cause": "not single_table"
+ }
+ }
+ }
+ ],
"attached_conditions_summary": [
{
"table": "three",
- "attached": "three.a is not null"
+ "attached": null
},
{
"table": "t1",
- "attached": "t1.b < 5000 and t1.c < 1000"
+ "attached": "t1.a = three.a and t1.b < 5000 and t1.c < 1000"
}
]
}
diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test
index e9ff91dce43..29da64616de 100644
--- a/mysql-test/main/opt_trace.test
+++ b/mysql-test/main/opt_trace.test
@@ -85,23 +85,7 @@ drop table t1,t2,t0;
--echo # group_by min max optimization
--echo #
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, KEY(a));
---disable_query_log
-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
+insert into t1 select seq, mod(seq,4)+1 from seq_1_to_65536;
analyze table 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);
ANALYZE TABLE t1;
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;
DROP TABLE t1;
@@ -138,10 +123,6 @@ drop table t1;
--echo # Late ORDER BY optimization
--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 (
pk int not null,
a int,
@@ -153,18 +134,16 @@ create table t1 (
KEY a_b(a,b)
);
-insert into t1
-select a, a,a,a, 'filler-dataaa' from test.one_k;
+insert into t1 select seq, seq,seq,seq, 'filler-dataaa' from seq_0_to_999;
update t1 set a=1 where pk between 0 and 180;
update t1 set b=2 where pk between 0 and 20;
analyze table t1;
-set optimizer_trace='enabled=on';
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';
explain select * from t1 where a=1 and b=2 order by c limit 1;
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
-drop table t1,ten,one_k;
+drop table t1;
--echo #
--echo # TABLE ELIMINATION
@@ -204,34 +183,23 @@ drop table t0, t1, t2, t3;
--echo # IN subquery to sem-join is traced
--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);
-insert into t1 values (0,0),(1,1),(2,2);
-create table t2 as select * from t1;
-
-create table t11(a int, b int);
+insert into t1 select seq,seq from seq_0_to_3;
-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;
+create table t2 (p int, a int);
+insert into t2 select seq,seq from seq_1_to_10;
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;
-drop table t0,t1,t11,t10,t12,t2;
+drop table t1,t2;
--echo #
--echo # Selectivities for columns and indexes.
--echo #
-create table t0 (a int);
-insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
-
create table t1 (
pk int,
a int,
@@ -239,7 +207,7 @@ b int,
key pk(pk),
key pk_a(pk,a),
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 ();
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;
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set @@use_stat_tables= @save_use_stat_tables;
-drop table t0,t1;
+drop table t1;
set optimizer_trace="enabled=off";
--echo #
@@ -942,7 +910,6 @@ set @save_histogram_size= @@histogram_size;
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set optimizer_switch='rowid_filter=on';
set use_stat_tables='preferably';
-set optimizer_use_condition_selectivity=4;
set histogram_size=127;
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;
@@ -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;
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
explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000;
+
drop table three, t1;
set @@optimizer_switch= @save_optimizer_switch;
diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result
index 7bf2a89705c..a042a621d91 100644
--- a/mysql-test/main/opt_trace_index_merge.result
+++ b/mysql-test/main/opt_trace_index_merge.result
@@ -73,7 +73,7 @@ explain select * from t1 where a=1 or b=1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 264.7939453
+ "cost": 0.1729314
},
"potential_range_indexes": [
{
@@ -98,7 +98,9 @@ explain select * from t1 where a=1 or b=1 {
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
},
- "analyzing_sort_intersect": {},
+ "analyzing_sort_intersect": {
+ "cutoff_cost": 0.1729314
+ },
"analyzing_index_merge_union": [
{
"indexes_to_merge": [
@@ -111,12 +113,12 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.745585794,
+ "cost": 0.001388369,
"chosen": true
}
],
"index_to_merge": "a",
- "cumulated_cost": 0.745585794
+ "cumulated_cost": 0.001388369
},
{
"range_scan_alternatives": [
@@ -127,15 +129,15 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.745585794,
+ "cost": 0.001388369,
"chosen": true
}
],
"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,
"cause": "always cheaper than non roworder retrieval",
"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,
"chosen": true
}
@@ -187,7 +189,7 @@ explain select * from t1 where a=1 or b=1 {
]
},
"rows_for_plan": 2,
- "cost_for_plan": 2.601171589,
+ "cost_for_plan": 0.005004612,
"chosen": true
}
}
@@ -218,17 +220,17 @@ explain select * from t1 where a=1 or b=1 {
{
"access_type": "index_merge",
"rows": 2,
- "rows_after_scan": 2,
"rows_after_filter": 2,
- "cost": 2.601171589,
+ "rows_out": 2,
+ "cost": 0.005004612,
"chosen": true
}
],
"chosen_access_method": {
"type": "index_merge",
- "records_read": 2,
- "records_out": 2,
- "cost": 2.601171589,
+ "rows_read": 2,
+ "rows_out": 2,
+ "cost": 0.005004612,
"uses_join_buffering": false
}
}
@@ -239,14 +241,14 @@ explain select * from t1 where a=1 or b=1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 2,
- "cost_for_plan": 2.601171589
+ "cost_for_plan": 0.005004612
}
]
},
{
"best_join_order": ["t1"],
"rows": 2,
- "cost": 2.601171589
+ "cost": 0.005004612
},
{
"substitute_best_equal": {
@@ -327,7 +329,7 @@ set optimizer_trace='enabled=on';
# 3-way ROR-intersection
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
-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;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
@@ -342,7 +344,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 1695.083937,
+ "cost": 2.770260666,
"chosen": true
},
{
@@ -353,7 +355,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 1695.083937,
+ "cost": 2.770260666,
"chosen": false,
"cause": "cost"
},
@@ -365,7 +367,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 1695.083937,
+ "cost": 2.770260666,
"chosen": false,
"cause": "cost"
}
@@ -376,10 +378,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key1",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 61.88893703,
- "disk_sweep_cost": 1682.25,
- "cumulative_total_cost": 1744.138937,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.240986767,
+ "disk_sweep_cost": 2.564386012,
+ "cumulative_total_cost": 2.805372779,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -387,10 +389,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key2",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 123.7778741,
- "disk_sweep_cost": 57.75,
- "cumulative_total_cost": 181.5278741,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.481973534,
+ "disk_sweep_cost": 0.088032868,
+ "cumulative_total_cost": 0.570006402,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -398,10 +400,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key3",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 185.6668111,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.722960301,
"disk_sweep_cost": 0,
- "cumulative_total_cost": 185.6668111,
+ "cumulative_total_cost": 0.722960301,
"usable": true,
"matching_rows_now": 2.687185191,
"intersect_covering_with_this_index": true,
@@ -415,12 +417,32 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index"
},
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"chosen": true
},
"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;
@@ -431,7 +453,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{
"type": "index_roworder_intersect",
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"clustered_pk_scan": false,
"intersect_of":
@@ -453,7 +475,23 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
]
},
"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
}
]
@@ -487,7 +525,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 517.508937,
+ "cost": 0.312832109,
"chosen": true
},
{
@@ -498,13 +536,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 517.508937,
+ "cost": 0.312832109,
"chosen": false,
"cause": "cost"
}
],
"index_to_merge": "key1",
- "cumulated_cost": 517.508937
+ "cumulated_cost": 0.312832109
},
{
"range_scan_alternatives":
@@ -517,7 +555,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 517.508937,
+ "cost": 0.312832109,
"chosen": true
},
{
@@ -528,16 +566,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 517.508937,
+ "cost": 0.312832109,
"chosen": false,
"cause": "cost"
}
],
"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,
"cause": "always cheaper than non roworder retrieval",
"analyzing_roworder_scans":
@@ -554,10 +592,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key1",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 61.88893703,
- "disk_sweep_cost": 1682.25,
- "cumulative_total_cost": 1744.138937,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.240986767,
+ "disk_sweep_cost": 2.564386012,
+ "cumulative_total_cost": 2.805372779,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -565,10 +603,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key2",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 123.7778741,
- "disk_sweep_cost": 57.75,
- "cumulative_total_cost": 181.5278741,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.481973534,
+ "disk_sweep_cost": 0.088032868,
+ "cumulative_total_cost": 0.570006402,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -581,7 +619,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index"
},
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"chosen": true
}
@@ -598,10 +636,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key3",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 61.88893703,
- "disk_sweep_cost": 1682.25,
- "cumulative_total_cost": 1744.138937,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.240986767,
+ "disk_sweep_cost": 2.564386012,
+ "cumulative_total_cost": 2.805372779,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -609,10 +647,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key4",
- "index_scan_cost": 61.88893703,
- "cumulated_index_scan_cost": 123.7778741,
- "disk_sweep_cost": 57.75,
- "cumulative_total_cost": 181.5278741,
+ "index_scan_cost": 0.240986767,
+ "cumulated_index_scan_cost": 0.481973534,
+ "disk_sweep_cost": 0.088032868,
+ "cumulative_total_cost": 0.570006402,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -625,13 +663,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index"
},
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"chosen": true
}
}
],
- "index_roworder_union_cost": 333.0257481,
+ "index_roworder_union_cost": 1.135493366,
"members": 2,
"chosen": true
}
@@ -650,7 +688,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{
"type": "index_roworder_intersect",
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"clustered_pk_scan": false,
"intersect_of":
@@ -674,7 +712,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{
"type": "index_roworder_intersect",
"rows": 77,
- "cost": 197.0550842,
+ "cost": 0.572490756,
"covering": false,
"clustered_pk_scan": false,
"intersect_of":
@@ -698,7 +736,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
]
},
"rows_for_plan": 154,
- "cost_for_plan": 333.0257481,
+ "cost_for_plan": 1.135493366,
"chosen": true
}
]
diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result
index d0a4f7cd24b..0b0f6f0d2fc 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -89,7 +89,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 253
+ "cost": 0.1764192
},
"potential_range_indexes": [
{
@@ -118,8 +118,9 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 252.02,
- "chosen": true
+ "cost": 0.19579056,
+ "chosen": false,
+ "cause": "cost"
},
{
"index": "key1",
@@ -128,7 +129,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.270146475,
+ "cost": 0.00415068,
"chosen": true
}
],
@@ -136,10 +137,10 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"intersecting_indexes": [
{
"index": "key1",
- "index_scan_cost": 0.525146475,
- "cumulated_index_scan_cost": 0.525146475,
- "disk_sweep_cost": 0.752076843,
- "cumulative_total_cost": 1.277223319,
+ "index_scan_cost": 0.001661605,
+ "cumulated_index_scan_cost": 0.001661605,
+ "disk_sweep_cost": 0.00171364,
+ "cumulative_total_cost": 0.003375245,
"usable": true,
"matching_rows_now": 1,
"intersect_covering_with_this_index": false,
@@ -151,7 +152,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"cause": "cost"
},
"chosen": false,
- "cause": "cost"
+ "cause": "too few indexes to merge"
},
"analyzing_index_merge_union": []
},
@@ -167,7 +168,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"ranges": ["(1) <= (key1) <= (1)"]
},
"rows_for_plan": 1,
- "cost_for_plan": 1.270146475,
+ "cost_for_plan": 0.00415068,
"chosen": true
}
}
@@ -177,7 +178,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"rowid_filters": [
{
"key": "key1",
- "build_cost": 0.526146475,
+ "build_cost": 0.000002653,
"rows": 1
}
]
@@ -215,7 +216,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"index": "key1",
"used_range_estimates": true,
"rows": 1,
- "cost": 1.250146475,
+ "cost": 0.00335956,
"chosen": true
},
{
@@ -226,9 +227,9 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
],
"chosen_access_method": {
"type": "ref",
- "records_read": 1,
- "records_out": 1,
- "cost": 1.250146475,
+ "rows_read": 1,
+ "rows_out": 1,
+ "cost": 0.00335956,
"uses_join_buffering": false
}
}
@@ -239,14 +240,14 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 1.250146475
+ "cost_for_plan": 0.00335956
}
]
},
{
"best_join_order": ["t1"],
"rows": 1,
- "cost": 1.250146475
+ "cost": 0.00335956
},
{
"substitute_best_equal": {
diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result
index f440aa381c3..d1b6900bddb 100644
--- a/mysql-test/main/opt_trace_security.result
+++ b/mysql-test/main/opt_trace_security.result
@@ -80,8 +80,8 @@ select * from db1.t1 {
"table": "t1",
"table_scan": {
"rows": 3,
- "read_cost": 0.010373215,
- "read_and_compare_cost": 0.010469215
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -103,7 +103,7 @@ select * from db1.t1 {
"rows": 3,
"rows_after_filter": 3,
"rows_out": 3,
- "cost": 0.010469215,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
@@ -112,7 +112,7 @@ select * from db1.t1 {
"type": "scan",
"rows_read": 3,
"rows_out": 3,
- "cost": 0.010469215,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -123,14 +123,14 @@ select * from db1.t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 0.010469215
+ "cost_for_plan": 0.010504815
}
]
},
{
"best_join_order": ["t1"],
"rows": 3,
- "cost": 0.010469215
+ "cost": 0.010504815
},
{
"attaching_conditions_to_tables": {
@@ -219,8 +219,8 @@ select * from db1.v1 {
"table": "t1",
"table_scan": {
"rows": 3,
- "read_cost": 0.010373215,
- "read_and_compare_cost": 0.010469215
+ "read_cost": 0.010408815,
+ "read_and_compare_cost": 0.010504815
}
}
]
@@ -242,7 +242,7 @@ select * from db1.v1 {
"rows": 3,
"rows_after_filter": 3,
"rows_out": 3,
- "cost": 0.010469215,
+ "cost": 0.010504815,
"index_only": false,
"chosen": true
}
@@ -251,7 +251,7 @@ select * from db1.v1 {
"type": "scan",
"rows_read": 3,
"rows_out": 3,
- "cost": 0.010469215,
+ "cost": 0.010504815,
"uses_join_buffering": false
}
}
@@ -262,14 +262,14 @@ select * from db1.v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 0.010469215
+ "cost_for_plan": 0.010504815
}
]
},
{
"best_join_order": ["t1"],
"rows": 3,
- "cost": 0.010469215
+ "cost": 0.010504815
},
{
"attaching_conditions_to_tables": {
diff --git a/mysql-test/main/opt_trace_selectivity.result b/mysql-test/main/opt_trace_selectivity.result
index bef3d62b0ce..60c0acc7216 100644
--- a/mysql-test/main/opt_trace_selectivity.result
+++ b/mysql-test/main/opt_trace_selectivity.result
@@ -53,7 +53,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "a",
"used_range_estimates": true,
"rows": 104,
- "cost": 78.54062004,
+ "cost": 0.060906438,
"chosen": true
},
{
@@ -61,7 +61,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b",
"used_range_estimates": true,
"rows": 340,
- "cost": 255.6327963,
+ "cost": 0.14153631,
"chosen": false,
"cause": "cost"
},
@@ -70,25 +70,25 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c",
"used_range_estimates": true,
"rows": 632,
- "cost": 475.2468449,
+ "cost": 0.241743894,
"chosen": false,
"cause": "cost"
},
{
"access_type": "index_merge",
"rows": 7,
- "rows_after_scan": 7,
"rows_after_filter": 7,
- "cost": 13.79559815,
+ "rows_out": 7,
+ "cost": 0.045367017,
"chosen": true
}
],
"chosen_access_method":
{
"type": "index_merge",
- "records_read": 7,
- "records_out": 7,
- "cost": 13.79559815,
+ "rows_read": 7,
+ "rows_out": 7,
+ "cost": 0.045367017,
"uses_join_buffering": false
}
}
@@ -100,7 +100,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t1",
"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",
"used_range_estimates": true,
"rows": 6,
- "cost": 5.002343464,
+ "cost": 0.005306142,
"chosen": true
},
{
@@ -156,7 +156,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b",
"used_range_estimates": true,
"rows": 232,
- "cost": 174.5906139,
+ "cost": 0.104637894,
"chosen": false,
"cause": "cost"
},
@@ -165,7 +165,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c",
"used_range_estimates": true,
"rows": 293,
- "cost": 220.3644392,
+ "cost": 0.125478666,
"chosen": false,
"cause": "cost"
},
@@ -178,9 +178,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method":
{
"type": "ref",
- "records_read": 6,
- "records_out": 0.6,
- "cost": 5.002343464,
+ "rows_read": 6,
+ "rows_out": 0.6,
+ "cost": 0.005306142,
"uses_join_buffering": false
}
}
@@ -191,10 +191,11 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"plan_prefix":
[],
"table": "t1",
- "rows_for_plan": 6,
- "cost_for_plan": 5.002343464,
- "selectivity": 0.1,
- "estimated_join_cardinality": 0.6
+ "rows_for_plan": 0.6,
+ "cost_for_plan": 0.005306142,
+ "pushdown_cond_selectivity": 0.1,
+ "filtered": 10,
+ "rows_out": 0.6
}
]
]
diff --git a/mysql-test/main/opt_tvc.result b/mysql-test/main/opt_tvc.result
index 8ec88f49997..c08c68eb7ee 100644
--- a/mysql-test/main/opt_tvc.result
+++ b/mysql-test/main/opt_tvc.result
@@ -530,11 +530,11 @@ a b
4 yq
explain extended select * from t3 where a in (1,4);
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 ref idx idx 5 tvc_0._col_1 3 100.00
+1 PRIMARY t3 ALL idx NULL NULL NULL 28 100.00 Using where
+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
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
set @@in_predicate_conversion_threshold= 4;
select * from t1 where (a,b) in ((1,2),(3,4));
diff --git a/mysql-test/main/optimizer_costs.result b/mysql-test/main/optimizer_costs.result
new file mode 100644
index 00000000000..a00673df02c
--- /dev/null
+++ b/mysql-test/main/optimizer_costs.result
@@ -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
diff --git a/mysql-test/main/optimizer_costs.test b/mysql-test/main/optimizer_costs.test
new file mode 100644
index 00000000000..13ce927fb26
--- /dev/null
+++ b/mysql-test/main/optimizer_costs.test
@@ -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
diff --git a/mysql-test/main/optimizer_costs2-master.opt b/mysql-test/main/optimizer_costs2-master.opt
new file mode 100644
index 00000000000..718ccafc05e
--- /dev/null
+++ b/mysql-test/main/optimizer_costs2-master.opt
@@ -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
diff --git a/mysql-test/main/optimizer_costs2.result b/mysql-test/main/optimizer_costs2.result
new file mode 100644
index 00000000000..688dcb51110
--- /dev/null
+++ b/mysql-test/main/optimizer_costs2.result
@@ -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
diff --git a/mysql-test/main/optimizer_costs2.test b/mysql-test/main/optimizer_costs2.test
new file mode 100644
index 00000000000..0445ce523cd
--- /dev/null
+++ b/mysql-test/main/optimizer_costs2.test
@@ -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;
diff --git a/mysql-test/main/order_by.result b/mysql-test/main/order_by.result
index b59089bee80..cb5459532ee 100644
--- a/mysql-test/main/order_by.result
+++ b/mysql-test/main/order_by.result
@@ -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
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
-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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k3 5 NULL 73 Using where
@@ -1577,19 +1580,20 @@ ANALYZE
"r_sort_mode": "sort_key,addon_fields",
"table": {
"table_name": "t1",
- "access_type": "index",
+ "access_type": "ref_or_null",
"possible_keys": ["a_c", "a"],
"key": "a_c",
"key_length": "10",
"used_key_parts": ["a", "c"],
+ "ref": ["const", "const"],
"r_loops": 1,
"rows": 2,
- "r_rows": 2,
+ "r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 50,
- "r_filtered": 50,
- "attached_condition": "t1.a = 2 and (t1.c = 10 or t1.c is null)",
+ "r_filtered": 100,
+ "attached_condition": "t1.c = 10 or t1.c is null",
"using_index": true
}
}
@@ -1601,26 +1605,11 @@ ANALYZE
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 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
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
col
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
EXPLAIN
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 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 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:
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;
@@ -3184,7 +3173,7 @@ id select_type table type possible_keys key key_len ref rows Extra
# See above query
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
-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;
#
# MDEV-8989: ORDER BY optimizer ignores equality propagation
@@ -3565,8 +3554,8 @@ WHERE books.library_id = 8663 AND
books.scheduled_for_removal=0 )
ORDER BY wings.id;
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 books ALL library_idx NULL NULL NULL 2 100.00 Using where; FirstMatch(wings); Using join buffer (flat, BNL join)
+1 PRIMARY wings ALL PRIMARY NULL NULL NULL 2 100.00 Using filesort
+1 PRIMARY books ref library_idx library_idx 4 const 2 50.00 Using where; FirstMatch(wings)
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`
set optimizer_switch= @save_optimizer_switch;
@@ -3700,8 +3689,8 @@ WHERE
t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY
t2.key2 ASC
-LIMIT 1)
-from t1;
+LIMIT 1) as "con"
+ from t1;
id select_type table type possible_keys key key_len ref rows Extra
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
@@ -3712,15 +3701,9 @@ WHERE
t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY
t2.key2 ASC
-LIMIT 1)
-from t1;
-(SELECT concat(id, '-', key1, '-', col1)
-FROM t2
-WHERE
-t2.key1 = t1.a and t2.key1 IS NOT NULL
-ORDER BY
-t2.key2 ASC
-LIMIT 1)
+LIMIT 1) as "con"
+ from t1;
+con
100-0-123456
101-1-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);
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);
-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
# the queries with GROUP BY and ORDER BY clause.
EXPLAIN SELECT t1.a
@@ -4471,9 +4455,9 @@ FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
ORDER BY t1.a DESC;
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 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 10 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 97 Using where
EXPLAIN FORMAT=JSON SELECT t1.a
FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
@@ -4484,48 +4468,46 @@ EXPLAIN
"select_id": 1,
"nested_loop": [
{
- "read_sorted_file": {
- "filesort": {
- "sort_key": "t1.a desc",
- "table": {
- "table_name": "<subquery2>",
- "access_type": "ALL",
- "possible_keys": ["distinct_key"],
- "rows": 5,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "nested_loop": [
- {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t2.b = 3 and t2.a is not null"
- }
- }
- ]
- }
- }
- }
- }
+ "table": {
+ "table_name": "t1",
+ "access_type": "index",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["a"],
+ "rows": 10,
+ "filtered": 100,
+ "using_index": true
}
},
{
"table": {
- "table_name": "t1",
+ "table_name": "<subquery2>",
"access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
"key_length": "4",
"used_key_parts": ["a"],
- "ref": ["test.t2.a"],
+ "ref": ["func"],
"rows": 1,
"filtered": 100,
- "using_index": true
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 97,
+ "filtered": 100,
+ "attached_condition": "t2.b = 3"
+ }
+ }
+ ]
+ }
+ }
}
}
]
@@ -4544,9 +4526,9 @@ FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
GROUP BY t1.a DESC;
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 eq_ref PRIMARY PRIMARY 4 test.t2.a 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 10 Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 97 Using where
EXPLAIN FORMAT=JSON SELECT t1.a, group_concat(t1.b)
FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
@@ -4561,43 +4543,43 @@ EXPLAIN
"filesort": {
"sort_key": "t1.a desc",
"table": {
- "table_name": "<subquery2>",
+ "table_name": "t1",
"access_type": "ALL",
- "possible_keys": ["distinct_key"],
- "rows": 5,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "nested_loop": [
- {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t2.b = 3 and t2.a is not null"
- }
- }
- ]
- }
- }
+ "possible_keys": ["PRIMARY"],
+ "rows": 10,
+ "filtered": 100
}
}
}
},
{
"table": {
- "table_name": "t1",
+ "table_name": "<subquery2>",
"access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
"key_length": "4",
"used_key_parts": ["a"],
- "ref": ["test.t2.a"],
+ "ref": ["func"],
"rows": 1,
- "filtered": 100
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 97,
+ "filtered": 100,
+ "attached_condition": "t2.b = 3"
+ }
+ }
+ ]
+ }
+ }
}
}
]
diff --git a/mysql-test/main/order_by.test b/mysql-test/main/order_by.test
index 24c90a62041..c336a6784a5 100644
--- a/mysql-test/main/order_by.test
+++ b/mysql-test/main/order_by.test
@@ -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
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
--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
@@ -2409,7 +2398,7 @@ let $query= select
t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY
t2.key2 ASC
- LIMIT 1)
+ LIMIT 1) as "con"
from t1;
--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),
(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 # the queries with GROUP BY and ORDER BY clause.
diff --git a/mysql-test/main/order_by_innodb.result b/mysql-test/main/order_by_innodb.result
index 7462b8e6688..11287f25698 100644
--- a/mysql-test/main/order_by_innodb.result
+++ b/mysql-test/main/order_by_innodb.result
@@ -256,7 +256,7 @@ d1 > '2019-02-06 00:00:00'
dd.d1, dd.d2, dd.id limit 1
);
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
2 DEPENDENT SUBQUERY dd ref id2,for_latest_sort id2 4 test.t1.id # Using where; Using filesort
drop table t1,t2,t3;
diff --git a/mysql-test/main/partition.result b/mysql-test/main/partition.result
index 0d37d4cb168..ad4c3cf1ad3 100644
--- a/mysql-test/main/partition.result
+++ b/mysql-test/main/partition.result
@@ -2361,11 +2361,11 @@ b c
EXPLAIN
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
-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
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
-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;
#
# Bug #45807: crash accessing partitioned table and sql_mode
diff --git a/mysql-test/main/partition_explicit_prune.result b/mysql-test/main/partition_explicit_prune.result
index 07af2d58a42..b7f4abe2952 100644
--- a/mysql-test/main/partition_explicit_prune.result
+++ b/mysql-test/main/partition_explicit_prune.result
@@ -470,7 +470,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE TableAlias p0-9_subp3 index NULL b 71 NULL 3 Using index
EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p10-99_subp4,p10-99_subp5 index NULL PRIMARY 4 NULL 2 Using index
+1 SIMPLE t1 p10-99_subp4,p10-99_subp5 index NULL b 71 NULL 2 Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1000000;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
@@ -1939,7 +1939,7 @@ MOD(seq, 100),
seq_1_to_5000;
explain select * from t1 partition (p1) where a=10 and b=10;
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
flush tables;
select * from t1 partition (p1)where a=10 and b=10;
pk a b filler
diff --git a/mysql-test/main/partition_mrr_aria.result b/mysql-test/main/partition_mrr_aria.result
index 7ff5c9b63ed..c7983007281 100644
--- a/mysql-test/main/partition_mrr_aria.result
+++ b/mysql-test/main/partition_mrr_aria.result
@@ -130,7 +130,7 @@ set optimizer_switch='mrr=on';
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition(BKA); Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = `test`.`t2`.`a` - 1
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
@@ -164,7 +164,7 @@ tp a b c a
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition; Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = 4
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
diff --git a/mysql-test/main/partition_mrr_innodb.result b/mysql-test/main/partition_mrr_innodb.result
index 98819021a6d..7d91fafef7c 100644
--- a/mysql-test/main/partition_mrr_innodb.result
+++ b/mysql-test/main/partition_mrr_innodb.result
@@ -130,7 +130,7 @@ set optimizer_switch='mrr=on';
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition(BKA); Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = `test`.`t2`.`a` - 1
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
@@ -164,7 +164,7 @@ tp a b c a
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition; Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = 4
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
diff --git a/mysql-test/main/partition_mrr_myisam.result b/mysql-test/main/partition_mrr_myisam.result
index c3ce2935417..9155851a60a 100644
--- a/mysql-test/main/partition_mrr_myisam.result
+++ b/mysql-test/main/partition_mrr_myisam.result
@@ -130,7 +130,7 @@ set optimizer_switch='mrr=on';
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition(BKA); Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = `test`.`t2`.`a` - 1
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = t2.a-1;
@@ -164,7 +164,7 @@ tp a b c a
explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range idx idx 5 NULL 2 100.00 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 100.00 Using index condition; Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 25.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t0`.`tp` AS `tp`,`test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t0`.`c` AS `c`,`test`.`t2`.`a` AS `a` from `test`.`t0` join `test`.`t2` where `test`.`t0`.`a` = `test`.`t2`.`a` and `test`.`t2`.`a` in (3,4) and `test`.`t0`.`b` / 10 = 4
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
@@ -288,7 +288,7 @@ explain
select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range idx idx 5 NULL 2 Using where; Using index
-1 SIMPLE t0 ref idx idx 5 test.t2.a 12 Using index condition; Using join buffer (flat, BKA join); Rowid-ordered scan
+1 SIMPLE t0 ALL idx NULL NULL NULL 50 Using where; Using join buffer (flat, BNL join)
# This will use "Using index condition(BKA)"
explain
select * from t1,t2 where t2.a in (3,4) and t1.a=t2.a and (t1.b / 10) = 4;
diff --git a/mysql-test/main/partition_pruning.result b/mysql-test/main/partition_pruning.result
index dcc25892276..7f07a6c4257 100644
--- a/mysql-test/main/partition_pruning.result
+++ b/mysql-test/main/partition_pruning.result
@@ -18,7 +18,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
# # # # range # # # # 3 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
id select_type table partitions type possible_keys key key_len ref rows Extra
-# # # # range # # # # 8 #
+# # # # index # # # # 10 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
# # # # range # # # # 3 #
@@ -92,7 +92,7 @@ a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 6;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,p5 range PRIMARY PRIMARY 4 NULL 7 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,p5 index PRIMARY PRIMARY 4 NULL 7 Using where; Using index
SELECT * FROM t1 WHERE a < 7;
a
-1
@@ -105,7 +105,7 @@ a
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max range PRIMARY PRIMARY 4 NULL 8 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index
SELECT * FROM t1 WHERE a <= 1;
a
-1
@@ -155,7 +155,7 @@ a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,p5 range PRIMARY PRIMARY 4 NULL 7 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,p5 index PRIMARY PRIMARY 4 NULL 7 Using where; Using index
SELECT * FROM t1 WHERE a <= 6;
a
-1
@@ -168,7 +168,7 @@ a
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 6;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max range PRIMARY PRIMARY 4 NULL 8 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index
SELECT * FROM t1 WHERE a <= 7;
a
-1
@@ -182,7 +182,7 @@ a
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 7;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max range PRIMARY PRIMARY 4 NULL 9 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 10 Using where; Using index
SELECT * FROM t1 WHERE a = 1;
a
1
@@ -237,7 +237,7 @@ a
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2,p3,p4,p5,max range PRIMARY PRIMARY 4 NULL 8 Using where; Using index
+1 SIMPLE t1 p1,p2,p3,p4,p5,max index PRIMARY PRIMARY 4 NULL 8 Using where; Using index
SELECT * FROM t1 WHERE a >= 2;
a
2
@@ -424,7 +424,7 @@ a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 6;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,max range PRIMARY PRIMARY 4 NULL 7 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index
SELECT * FROM t1 WHERE a <= 1;
a
-1
@@ -474,7 +474,7 @@ a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,max range PRIMARY PRIMARY 4 NULL 7 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index
SELECT * FROM t1 WHERE a <= 6;
a
-1
@@ -487,7 +487,7 @@ a
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 6;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p0,p1,p2,p3,p4,max range PRIMARY PRIMARY 4 NULL 8 Using where; Using index
+1 SIMPLE t1 p0,p1,p2,p3,p4,max index PRIMARY PRIMARY 4 NULL 9 Using where; Using index
SELECT * FROM t1 WHERE a = 1;
a
1
@@ -2888,12 +2888,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b in (2,4,6);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 range b b 5 NULL 231 100.00 Using where
+1 SIMPLE t2 ALL b NULL NULL NULL 910 25.38 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` in (2,4,6)
explain partitions select * from t2 where b in (2,4,6);
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 231 Using where
+1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b in (7,8,9);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL b NULL NULL NULL 910 36.81 Using where
@@ -2912,12 +2912,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b > 5 and b < 8;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 range b b 5 NULL 202 100.00 Using where
+1 SIMPLE t2 ALL b NULL NULL NULL 910 22.20 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` > 5 and `test`.`t2`.`b` < 8
explain partitions select * from t2 where b > 5 and b < 8;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 202 Using where
+1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b > 5 and b < 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range b b 5 NULL 77 100.00 Using where
@@ -2946,10 +2946,10 @@ flush status;
update t2 set a = 111 where b in (5,6);
show status like 'Handler_read_rnd_next';
Variable_name Value
-Handler_read_rnd_next 0
+Handler_read_rnd_next 915
show status like 'Handler_read_key';
Variable_name Value
-Handler_read_key 10
+Handler_read_key 0
flush status;
update t2 set a = 222 where b = 7;
show status like 'Handler_read_rnd_next';
@@ -3378,7 +3378,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1 const PRIMARY PRIMARY 8 const,const 1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 >= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
+1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 > 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
@@ -3387,7 +3387,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1 range PRIMARY PRIMARY 8 NULL 2 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 <= 3;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
+1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 3;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
@@ -3405,7 +3405,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 4;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
+1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 = 4;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p2 const PRIMARY PRIMARY 8 const,const 1
@@ -3465,7 +3465,7 @@ select * from t1
where company_id = 1000
and dept_id in (select dept_id from t2 where COMPANY_ID = 1000);
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 p_1000 ALL PRIMARY NULL NULL NULL 6 Using where
+1 PRIMARY t1 p_1000 ref PRIMARY PRIMARY 8 const 6 Using where
1 PRIMARY t2 p_1000 eq_ref PRIMARY PRIMARY 16 const,test.t1.dept_id 1 Using index
drop table t1,t2;
#
diff --git a/mysql-test/main/partition_range.result b/mysql-test/main/partition_range.result
index 3c1ff311bf5..be1689b218e 100644
--- a/mysql-test/main/partition_range.result
+++ b/mysql-test/main/partition_range.result
@@ -19,11 +19,11 @@ insert into t1 (a,b) select seq,seq from seq_4001_to_4100;
insert into t1 (a,b) select seq,seq from seq_10001_to_10100;
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
+1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
alter table t1 partition by hash(a) partitions 1;
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
+1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
DROP TABLE t1;
create table t1 (a DATETIME)
partition by range (TO_DAYS(a))
@@ -958,6 +958,11 @@ CREATE TABLE t1 (
a INT,
b INT,
KEY ( a, b )
+);
+CREATE TABLE t1_part (
+a INT,
+b INT,
+KEY ( a, b )
) PARTITION BY HASH (a) PARTITIONS 1;
CREATE TABLE t2 (
a INT,
@@ -969,36 +974,68 @@ INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
+INSERT INTO t1 values(10,0),(10,1),(10,2),(100,0),(100,1);
+select count(*) from t1;
+count(*)
+85
+select count(*) from t1 where a=10;
+count(*)
+4
+select count(*) from t1 where a=100;
+count(*)
+2
+INSERT INTO t1_part SELECT * FROM t1;
INSERT INTO t2 SELECT * FROM t1;
-ANALYZE TABLE t1,t2;
+ANALYZE TABLE t1_part,t2;
Table Op Msg_type Msg_text
-test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze status OK
+test.t1_part analyze status Engine-independent statistics collected
+test.t1_part analyze status OK
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status Table is already up to date
# plans should be identical
-EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
+EXPLAIN SELECT a, MAX(b) FROM t1_part WHERE a IN (10,100) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 2 Using where; Using index
+1 SIMPLE t1_part range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index
+1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
FLUSH status;
-SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
+SELECT a, MAX(b) FROM t1_part WHERE a IN (10, 100) GROUP BY a;
a MAX(b)
10 10
-# Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
+100 1
+SHOW status LIKE 'handler_read%';
Variable_name Value
-Handler_read_key 2
+Handler_read_first 0
+Handler_read_key 6
+Handler_read_last 1
+Handler_read_next 0
+Handler_read_prev 0
+Handler_read_retry 0
+Handler_read_rnd 0
+Handler_read_rnd_deleted 0
+Handler_read_rnd_next 0
FLUSH status;
SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
a MAX(b)
10 10
-# Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
+100 1
+SHOW status LIKE 'handler_read%';
Variable_name Value
-Handler_read_key 2
+Handler_read_first 0
+Handler_read_key 6
+Handler_read_last 1
+Handler_read_next 0
+Handler_read_prev 0
+Handler_read_retry 0
+Handler_read_rnd 0
+Handler_read_rnd_deleted 0
+Handler_read_rnd_next 0
+insert into t2 select 100,seq from seq_1_to_100;
+EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
+DROP TABLE t1,t1_part,t2;
#
# MDEV-18501 Partition pruning doesn't work for historical queries
#
@@ -1026,7 +1063,7 @@ d
select * from t1 partition (p1);
d
2000-01-01 00:00:01.000000
-DROP TABLE t1, t2;
+DROP TABLE t1;
#
# MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column
#
diff --git a/mysql-test/main/partition_range.test b/mysql-test/main/partition_range.test
index 740cbcd7d7b..cfd2b42513f 100644
--- a/mysql-test/main/partition_range.test
+++ b/mysql-test/main/partition_range.test
@@ -942,10 +942,17 @@ drop table t1, t2;
--echo # Bug#50939: Loose Index Scan unduly relies on engine to remember range
--echo # endpoints
--echo #
+
CREATE TABLE t1 (
a INT,
b INT,
KEY ( a, b )
+);
+
+CREATE TABLE t1_part (
+ a INT,
+ b INT,
+ KEY ( a, b )
) PARTITION BY HASH (a) PARTITIONS 1;
CREATE TABLE t2 (
@@ -960,24 +967,32 @@ INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
+INSERT INTO t1 values(10,0),(10,1),(10,2),(100,0),(100,1);
+select count(*) from t1;
+select count(*) from t1 where a=10;
+select count(*) from t1 where a=100;
+INSERT INTO t1_part SELECT * FROM t1;
INSERT INTO t2 SELECT * FROM t1;
-ANALYZE TABLE t1,t2;
+ANALYZE TABLE t1_part,t2;
--echo # plans should be identical
-EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
+EXPLAIN SELECT a, MAX(b) FROM t1_part WHERE a IN (10,100) GROUP BY a;
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
FLUSH status;
-SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
---echo # Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
+SELECT a, MAX(b) FROM t1_part WHERE a IN (10, 100) GROUP BY a;
+SHOW status LIKE 'handler_read%';
FLUSH status;
SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
---echo # Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
+SHOW status LIKE 'handler_read%';
+
+insert into t2 select 100,seq from seq_1_to_100;
+EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
+
+DROP TABLE t1,t1_part,t2;
--echo #
--echo # MDEV-18501 Partition pruning doesn't work for historical queries
@@ -1006,7 +1021,7 @@ insert into t1 values
select * from t1 partition (p0);
select * from t1 partition (p1);
-DROP TABLE t1, t2;
+DROP TABLE t1;
--echo #
--echo # MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column
diff --git a/mysql-test/main/percona_nonflushing_analyze_debug.result b/mysql-test/main/percona_nonflushing_analyze_debug.result
index 78da085f26f..c3388fa42ed 100644
--- a/mysql-test/main/percona_nonflushing_analyze_debug.result
+++ b/mysql-test/main/percona_nonflushing_analyze_debug.result
@@ -1,7 +1,7 @@
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1), (2), (3);
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";
SELECT * FROM t1;
connection default;
SET DEBUG_SYNC="now WAIT_FOR idx_scan_in_progress";
diff --git a/mysql-test/main/pool_of_threads.result b/mysql-test/main/pool_of_threads.result
index 91ad7ab098f..718cb7dc8ce 100644
--- a/mysql-test/main/pool_of_threads.result
+++ b/mysql-test/main/pool_of_threads.result
@@ -1,5 +1,6 @@
SET optimizer_switch='outer_join_with_cache=off';
drop table if exists t1,t2,t3,t4;
+set @@default_storage_engine="aria";
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' 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
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
+#
+# Some test with ORDER BY and limit
+#
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
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 '',
PRIMARY KEY (companynr),
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;
companynr companyname
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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
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;
id select_type table type possible_keys key key_len ref rows Extra
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
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
-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
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
-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
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
-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
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
@@ -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
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
-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
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
-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
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
diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result
index a2ecc66c570..0bd56723d4b 100644
--- a/mysql-test/main/range.result
+++ b/mysql-test/main/range.result
@@ -252,7 +252,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref x x 5 const 1 Using index
explain select count(*) from t1 where x in (1,2,3,4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
+1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index
drop table t1;
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
@@ -261,12 +261,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
explain select * from t1 force index(i1), t2 force index(j1) where
(t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
CREATE TABLE t1 (
a int(11) default NULL,
@@ -281,7 +281,7 @@ INSERT INTO t1 VALUES
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter
+1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 2 (41%) Using index condition; Using where; Using rowid filter
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
a b
DROP TABLE t1;
@@ -309,6 +309,9 @@ a b
15 1
47 1
DROP TABLE t1;
+#
+# Test of problem with IN on many different keyparts. (Bug #4157)
+#
CREATE TABLE t1 (
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
line int( 5 ) unsigned NOT NULL default '0',
@@ -325,10 +328,17 @@ KEY `LINES` ( owner, tableid, content, id ) ,
KEY recount( owner, line )
) ENGINE = MYISAM;
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
+INSERT into t1 (owner,id,columnid,line) select 11,seq+20,seq,seq from seq_1_to_100;
+explain SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref PRIMARY,menu,COLUMN,LINES,recount COLUMN 4 const 11 Using index condition
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
id columnid tableid content showid line ordinal
-15 15 1 188 1 1 0
13 13 1 188 1 5 0
+15 15 1 188 1 1 0
+33 13 1 188 1 13 0
+34 14 1 188 1 14 0
+35 15 1 188 1 15 0
drop table t1;
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
@@ -676,7 +686,7 @@ create table t1(a char(2), key(a(1)));
insert into t1 values ('x'), ('xx');
explain select a from t1 where a > 'x';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where
+1 SIMPLE t1 range a a 2 NULL 2 Using where
select a from t1 where a > 'x';
a
xx
@@ -723,7 +733,7 @@ WHERE
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE v ALL OXLEFT,OXRIGHT,OXROOTID NULL NULL NULL 12 Using where
+1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 6 Using index condition
1 SIMPLE s ALL OXLEFT NULL NULL NULL 12 Range checked for each record (index map: 0x4)
SELECT s.oxid FROM t1 v, t1 s
WHERE
@@ -1138,7 +1148,7 @@ INSERT INTO t1 VALUES
('A2','2005-12-01 08:00:00',1000);
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where
+1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
item started price
Warnings:
@@ -1236,13 +1246,16 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2 limit 250;
+insert into t2 select 1000, b, 'filler' from t2 limit 50;
+select count(*) from t2;
+count(*)
+550
alter table t2 add index (a,b);
-# In following EXPLAIN the access method should be ref, #rows~=250
+# In following EXPLAIN the access method should be ref, #rows~=50
# (and not 2) when we are not using rowid-ordered scans
explain select * from t2 where a=1000 and b<11;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range a a 10 NULL 253 Using index condition
+1 SIMPLE t2 range a a 10 NULL 63 Using index condition
drop table t1, t2;
CREATE TABLE t1( a INT, b INT, KEY( a, b ) );
CREATE TABLE t2( a INT, b INT, KEY( a, b ) );
@@ -1954,7 +1967,7 @@ select count(*) from t2 left join t1
on (t1.key1 < 3 or t1.key1 between 920 and 930) and t1.key2 < 1000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 64
-1 SIMPLE t1 range i1,i2 i1 4 NULL 12 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t1 range|filter i1,i2 i1|i2 4|4 NULL 12 (89%) Using where; Using join buffer (flat, BNL join); Using rowid filter
select count(*) from t2 left join t1
on (t1.key1 < 3 or t1.key1 between 920 and 930) and t1.key2 < 1000;
count(*)
@@ -2541,7 +2554,7 @@ insert into t2 values
explain select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(2,2));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range idx1,idx2 idx1 5 NULL 3 Using index condition; Using where
+1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 3 (60%) Using index condition; Using where; Using rowid filter
1 SIMPLE t1 ref idx idx 5 test.t2.d 8
explain format=json select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(2,2));
@@ -2558,8 +2571,16 @@ EXPLAIN
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
+ "rowid_filter": {
+ "range": {
+ "key": "idx2",
+ "used_key_parts": ["e"]
+ },
+ "rows": 12,
+ "selectivity_pct": 60
+ },
"rows": 3,
- "filtered": 100,
+ "filtered": 60,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))"
}
@@ -2619,8 +2640,8 @@ insert into t2 values
explain select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range idx idx 5 NULL 6 Using index condition
-1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (14%) Using where; Using rowid filter
+1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 8 (14%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t1 ref idx idx 5 test.t2.d 8
explain format=json select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
EXPLAIN
@@ -2630,26 +2651,12 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "t1",
- "access_type": "range",
- "possible_keys": ["idx"],
- "key": "idx",
- "key_length": "5",
- "used_key_parts": ["a"],
- "rows": 6,
- "filtered": 100,
- "index_condition": "t1.a is not null"
- }
- },
- {
- "table": {
"table_name": "t2",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": ["idx1", "idx2"],
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
- "ref": ["test.t1.a"],
"rowid_filter": {
"range": {
"key": "idx2",
@@ -2658,9 +2665,23 @@ EXPLAIN
"rows": 15,
"selectivity_pct": 14.42307692
},
- "rows": 12,
+ "rows": 8,
"filtered": 14.42307663,
- "attached_condition": "(t1.a,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
+ "index_condition": "t2.d is not null",
+ "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
+ }
+ },
+ {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ref",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "5",
+ "used_key_parts": ["a"],
+ "ref": ["test.t2.d"],
+ "rows": 8,
+ "filtered": 73.17073059
}
}
]
@@ -2689,40 +2710,40 @@ prepare stmt from "select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1";
execute stmt;
a b c d e f
-3 2 uuuw 3 3 i
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
execute stmt;
a b c d e f
-3 2 uuuw 3 3 i
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
deallocate prepare stmt;
insert into t1 select * from t1;
# join order: (t2,t1) with ref access of t1
@@ -2730,8 +2751,8 @@ insert into t1 select * from t1;
explain select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range idx idx 5 NULL 15 Using index condition
-1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (7%) Using where; Using rowid filter
+1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 7 (7%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t1 ref idx idx 5 test.t2.d 11
explain format=json select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
EXPLAIN
@@ -2741,26 +2762,12 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "t1",
- "access_type": "range",
- "possible_keys": ["idx"],
- "key": "idx",
- "key_length": "5",
- "used_key_parts": ["a"],
- "rows": 15,
- "filtered": 100,
- "index_condition": "t1.a is not null"
- }
- },
- {
- "table": {
"table_name": "t2",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": ["idx1", "idx2"],
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
- "ref": ["test.t1.a"],
"rowid_filter": {
"range": {
"key": "idx2",
@@ -2769,9 +2776,23 @@ EXPLAIN
"rows": 7,
"selectivity_pct": 6.730769231
},
- "rows": 12,
+ "rows": 7,
"filtered": 6.730769157,
- "attached_condition": "(t1.a,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
+ "index_condition": "t2.d is not null",
+ "attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
+ }
+ },
+ {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ref",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "5",
+ "used_key_parts": ["a"],
+ "ref": ["test.t2.d"],
+ "rows": 11,
+ "filtered": 100
}
}
]
@@ -3372,7 +3393,7 @@ insert into t2 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C where A.a +
# expected type=range, rows=1487 , reason=using index dives
analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 range a a 5 NULL 1487 1199.00 100.00 100.00 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 2000 2000.00 74.35 59.95 Using where; Using index
insert into t2 values (200),(201);
# expected type=range, rows=201 , reason=using index statistics
analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,200,201);
diff --git a/mysql-test/main/range.test b/mysql-test/main/range.test
index a8c56fcc35c..2dc110c1422 100644
--- a/mysql-test/main/range.test
+++ b/mysql-test/main/range.test
@@ -3,6 +3,8 @@
# Problem with range optimizer
#
--source include/have_innodb.inc
+--source include/have_sequence.inc
+
SET optimizer_use_condition_selectivity=4;
set @innodb_stats_persistent_save= @@innodb_stats_persistent;
@@ -263,9 +265,9 @@ WHERE
);
DROP TABLE t1;
-#
-# Test of problem with IN on many different keyparts. (Bug #4157)
-#
+--echo #
+--echo # Test of problem with IN on many different keyparts. (Bug #4157)
+--echo #
CREATE TABLE t1 (
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
@@ -284,7 +286,10 @@ KEY recount( owner, line )
) ENGINE = MYISAM;
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
+INSERT into t1 (owner,id,columnid,line) select 11,seq+20,seq,seq from seq_1_to_100;
+explain SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
+--sorted_result
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
drop table t1;
@@ -1025,7 +1030,8 @@ create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2 limit 250;
+insert into t2 select 1000, b, 'filler' from t2 limit 50;
+select count(*) from t2;
alter table t2 add index (a,b);
# t2 values
# ( 1 , 10, 'filler')
@@ -1033,11 +1039,11 @@ alter table t2 add index (a,b);
# ( 3 , 10, 'filler')
# (... , 10, 'filler')
# ...
-# (1000, 10, 'filler') - 250 times
+# (1000, 10, 'filler') - 100 times
-# 250 rows, 1 row
+# 50 rows, 1 row
---echo # In following EXPLAIN the access method should be ref, #rows~=250
+--echo # In following EXPLAIN the access method should be ref, #rows~=50
--echo # (and not 2) when we are not using rowid-ordered scans
explain select * from t2 where a=1000 and b<11;
@@ -1984,7 +1990,9 @@ eval explain format=json $q5;
--sorted_result
eval $q5;
eval prepare stmt from "$q5";
+--sorted_result
execute stmt;
+--sorted_result
execute stmt;
deallocate prepare stmt;
diff --git a/mysql-test/main/range_innodb.result b/mysql-test/main/range_innodb.result
index 011ae411b21..826c0e4d90a 100644
--- a/mysql-test/main/range_innodb.result
+++ b/mysql-test/main/range_innodb.result
@@ -53,8 +53,8 @@ set optimizer_switch='extended_keys=on';
explain
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL #
-1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t1 ref PRIMARY,idx1,idx2 idx1 5 const #
+1 SIMPLE t2 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (incremental, BNL join)
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
pk a b
@@ -98,7 +98,7 @@ SET @saved_dbug = @@GLOBAL.debug_dbug;
set @@global.debug_dbug="+d,ha_index_init_fail";
explain select * from t1 where a=10 and b=10;
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 50 (2%) Using where; Using rowid filter
select * from t1 where a=10 and b=10;
ERROR HY000: Table definition has changed, please retry transaction
DROP TABLE t0,t1;
diff --git a/mysql-test/main/range_interrupted-13751.result b/mysql-test/main/range_interrupted-13751.result
index 68610cdda8e..eadd32bffa0 100644
--- a/mysql-test/main/range_interrupted-13751.result
+++ b/mysql-test/main/range_interrupted-13751.result
@@ -1,11 +1,11 @@
CREATE TABLE t1 (i INT AUTO_INCREMENT, c VARCHAR(1), KEY(i), KEY(c,i)) ENGINE=MyISAM;
-INSERT INTO t1 (c) VALUES ('a'),('b'),('c'),('d');
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
+INSERT INTO t1 (c) select mid("abcdefgh", mod(seq,8)+1, 1) from seq_1_to_256;
+explain SELECT 1 FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
+WHERE alias1.c = alias2.c OR alias1.i <= 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE alias2 index c c 8 NULL 256 Using index
+1 SIMPLE alias3 index NULL i 4 NULL 256 Using index; Using join buffer (flat, BNL join)
+1 SIMPLE alias1 ALL i,c NULL NULL NULL 256 Range checked for each record (index map: 0x3)
set @old_dbug=@@session.debug_dbug;
SET debug_dbug="+d,kill_join_init_read_record";
SELECT 1 FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
diff --git a/mysql-test/main/range_interrupted-13751.test b/mysql-test/main/range_interrupted-13751.test
index b0793edeb9d..939f15b2145 100644
--- a/mysql-test/main/range_interrupted-13751.test
+++ b/mysql-test/main/range_interrupted-13751.test
@@ -1,17 +1,15 @@
--- source include/have_debug.inc
+--source include/have_debug.inc
--source include/default_optimizer_switch.inc
+--source include/have_sequence.inc
#
# MDEV-13751 Interrupted SELECT fails with 1030: 'Got error 1 "Operation not permitted" from storage engine MyISAM'
#
CREATE TABLE t1 (i INT AUTO_INCREMENT, c VARCHAR(1), KEY(i), KEY(c,i)) ENGINE=MyISAM;
-INSERT INTO t1 (c) VALUES ('a'),('b'),('c'),('d');
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
-INSERT INTO t1 (c) SELECT c FROM t1;
+INSERT INTO t1 (c) select mid("abcdefgh", mod(seq,8)+1, 1) from seq_1_to_256;
+
+explain SELECT 1 FROM t1 AS alias1, t1 AS alias2, t1 AS alias3
+WHERE alias1.c = alias2.c OR alias1.i <= 1;
set @old_dbug=@@session.debug_dbug;
SET debug_dbug="+d,kill_join_init_read_record";
diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result
index a3c8bb7b8c2..1373faedf8e 100644
--- a/mysql-test/main/range_mrr_icp.result
+++ b/mysql-test/main/range_mrr_icp.result
@@ -255,7 +255,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref x x 5 const 1 Using index
explain select count(*) from t1 where x in (1,2,3,4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
+1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index
drop table t1;
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
@@ -264,12 +264,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
explain select * from t1 force index(i1), t2 force index(j1) where
(t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
CREATE TABLE t1 (
a int(11) default NULL,
@@ -312,6 +312,9 @@ a b
15 1
47 1
DROP TABLE t1;
+#
+# Test of problem with IN on many different keyparts. (Bug #4157)
+#
CREATE TABLE t1 (
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
line int( 5 ) unsigned NOT NULL default '0',
@@ -328,10 +331,17 @@ KEY `LINES` ( owner, tableid, content, id ) ,
KEY recount( owner, line )
) ENGINE = MYISAM;
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
+INSERT into t1 (owner,id,columnid,line) select 11,seq+20,seq,seq from seq_1_to_100;
+explain SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref PRIMARY,menu,COLUMN,LINES,recount COLUMN 4 const 11 Using index condition
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
id columnid tableid content showid line ordinal
-15 15 1 188 1 1 0
13 13 1 188 1 5 0
+15 15 1 188 1 1 0
+33 13 1 188 1 13 0
+34 14 1 188 1 14 0
+35 15 1 188 1 15 0
drop table t1;
create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
@@ -679,7 +689,7 @@ create table t1(a char(2), key(a(1)));
insert into t1 values ('x'), ('xx');
explain select a from t1 where a > 'x';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where
+1 SIMPLE t1 range a a 2 NULL 2 Using where
select a from t1 where a > 'x';
a
xx
@@ -726,7 +736,7 @@ WHERE
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE v ALL OXLEFT,OXRIGHT,OXROOTID NULL NULL NULL 12 Using where
+1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 6 Using index condition
1 SIMPLE s ALL OXLEFT NULL NULL NULL 12 Range checked for each record (index map: 0x4)
SELECT s.oxid FROM t1 v, t1 s
WHERE
@@ -1141,7 +1151,7 @@ INSERT INTO t1 VALUES
('A2','2005-12-01 08:00:00',1000);
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where
+1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
item started price
Warnings:
@@ -1239,13 +1249,16 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2 limit 250;
+insert into t2 select 1000, b, 'filler' from t2 limit 50;
+select count(*) from t2;
+count(*)
+550
alter table t2 add index (a,b);
-# In following EXPLAIN the access method should be ref, #rows~=250
+# In following EXPLAIN the access method should be ref, #rows~=50
# (and not 2) when we are not using rowid-ordered scans
explain select * from t2 where a=1000 and b<11;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range a a 10 NULL 253 Using index condition; Rowid-ordered scan
+1 SIMPLE t2 range a a 10 NULL 63 Using index condition; Rowid-ordered scan
drop table t1, t2;
CREATE TABLE t1( a INT, b INT, KEY( a, b ) );
CREATE TABLE t2( a INT, b INT, KEY( a, b ) );
@@ -2565,7 +2578,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 3,
- "filtered": 100,
+ "filtered": 60,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))",
"mrr_type": "Rowid-ordered scan"
@@ -2644,7 +2657,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 8,
- "filtered": 100,
+ "filtered": 14.42307663,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1",
"mrr_type": "Rowid-ordered scan"
@@ -2660,7 +2673,7 @@ EXPLAIN
"used_key_parts": ["a"],
"ref": ["test.t2.d"],
"rows": 8,
- "filtered": 100
+ "filtered": 73.17073059
}
}
]
@@ -2689,40 +2702,40 @@ prepare stmt from "select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1";
execute stmt;
a b c d e f
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuua 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzza 3 3 i
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-3 2 uuuw 3 3 i
-3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
+7 8 xxxxx 7 7 h
execute stmt;
a b c d e f
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuua 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzza 3 3 i
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-3 2 uuuw 3 3 i
-3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
+7 8 xxxxx 7 7 h
deallocate prepare stmt;
insert into t1 select * from t1;
# join order: (t2,t1) with ref access of t1
@@ -2748,7 +2761,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 7,
- "filtered": 100,
+ "filtered": 6.730769157,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1",
"mrr_type": "Rowid-ordered scan"
@@ -3369,7 +3382,7 @@ insert into t2 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C where A.a +
# expected type=range, rows=1487 , reason=using index dives
analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 range a a 5 NULL 1487 1199.00 100.00 100.00 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 2000 2000.00 74.35 59.95 Using where; Using index
insert into t2 values (200),(201);
# expected type=range, rows=201 , reason=using index statistics
analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,200,201);
diff --git a/mysql-test/main/range_notembedded.result b/mysql-test/main/range_notembedded.result
index b3d2dfbb43b..d774c81d6e1 100644
--- a/mysql-test/main/range_notembedded.result
+++ b/mysql-test/main/range_notembedded.result
@@ -13,7 +13,7 @@ set @tmp_21958=@@optimizer_trace;
set optimizer_trace=1;
explain select * from t2 where key1 in (1,2,3) and pk not in (1,2,3);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL PRIMARY,key1 NULL NULL NULL 5 Using where
+1 SIMPLE t2 range PRIMARY,key1 key1 5 NULL 3 Using index condition
# This should show only ranges in form "(1) <= (key1) <= (1)"
# ranges over "pk" should not be constructed.
select json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
@@ -24,6 +24,12 @@ json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
"(1) <= (key1) <= (1)",
"(2) <= (key1) <= (2)",
"(3) <= (key1) <= (3)"
+ ],
+
+ [
+ "(1) <= (key1) <= (1)",
+ "(2) <= (key1) <= (2)",
+ "(3) <= (key1) <= (3)"
]
]
set optimizer_trace=@tmp_21958;
diff --git a/mysql-test/main/range_vs_index_merge.result b/mysql-test/main/range_vs_index_merge.result
index 3babbc989b3..19848d6d388 100644
--- a/mysql-test/main/range_vs_index_merge.result
+++ b/mysql-test/main/range_vs_index_merge.result
@@ -333,7 +333,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN
SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City range PRIMARY PRIMARY 4 NULL 1200 Using index condition
+1 SIMPLE City ALL PRIMARY NULL NULL NULL 4079 Using where
EXPLAIN
SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG';
id select_type table type possible_keys key key_len ref rows Extra
@@ -1325,11 +1325,11 @@ WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H'))
AND (Population >= 100000 AND Population < 120000)
ORDER BY Population LIMIT 5;
ID Name Country Population
+3792 Tartu EST 101246
+518 Basildon GBR 100924
519 Worthing GBR 100000
638 al-Arish EGY 100447
-518 Basildon GBR 100924
707 Marbella ESP 101144
-3792 Tartu EST 101246
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
@@ -1750,6 +1750,9 @@ SELECT * FROM t1,t2,t3
WHERE (t2.f3 = 1 OR t3.f1=t2.f1) AND t3.f1 <> t2.f2 AND t3.f2 = t2.f4;
f1 f1 f2 f3 f4 f1 f2
DROP TABLE t1,t2,t3;
+#
+# LP bug #823301: index merge sort union with possible index scan
+#
CREATE TABLE t1 (
a int, b int, c int, d int,
PRIMARY KEY(b), INDEX idx1(d), INDEX idx2(d,b,c)
@@ -1766,7 +1769,7 @@ EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL 9 Using where
+1 SIMPLE t1 range PRIMARY,idx1,idx2 idx1 5 NULL 5 Using index condition; Using where
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
a b c d
@@ -1780,7 +1783,7 @@ EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL 9 Using where
+1 SIMPLE t1 range PRIMARY,idx1,idx2 idx1 5 NULL 5 Using index condition; Using where
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
a b c d
@@ -1894,7 +1897,7 @@ INDEX (Percentage)
DROP INDEX Country ON City;
CREATE INDEX CountryName ON City(Country,Name);
CREATE INDEX Name ON City(Name);
-select * from City
+explain select * from City
where
Country='FIN' AND Name IN ('Lahti','Imatra') OR
Country='RUS' AND Name IN ('St Petersburg', 'Moscow') OR
@@ -1906,26 +1909,9 @@ Country='FRA' AND Name IN ('Paris', 'Marcel') OR
Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR
Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
Country='ITA' AND Name IN ('Napoli', 'Venezia');
-ID Name Country Population
-175 Antwerpen BEL 446525
-176 Gent BEL 224180
-3068 Berlin DEU 3386667
-3087 Bonn DEU 301048
-3242 Lahti FIN 96921
-2974 Paris FRA 2125246
-1466 Napoli ITA 1002619
-1474 Venezia ITA 277305
-2808 Bergen NOR 230948
-2807 Oslo NOR 508726
-2928 Warszawa POL 1615369
-2931 Wroclaw POL 636765
-2918 Braga PRT 90535
-2915 Porto PRT 273060
-3580 Moscow RUS 8389200
-3581 St Petersburg RUS 4694000
-3048 Stockholm SWE 750348
-3051 Uppsala SWE 189569
-explain select * from City
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range CountryName,Name CountryName 38 NULL 20 Using index condition
+select * from City
where
Country='FIN' AND Name IN ('Lahti','Imatra') OR
Country='RUS' AND Name IN ('St Petersburg', 'Moscow') OR
@@ -1937,7 +1923,24 @@ Country='FRA' AND Name IN ('Paris', 'Marcel') OR
Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR
Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
Country='ITA' AND Name IN ('Napoli', 'Venezia');
-id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City range CountryName,Name CountryName 38 NULL 20 Using index condition
+ID Name Country Population
+1466 Napoli ITA 1002619
+1474 Venezia ITA 277305
+175 Antwerpen BEL 446525
+176 Gent BEL 224180
+2807 Oslo NOR 508726
+2808 Bergen NOR 230948
+2915 Porto PRT 273060
+2918 Braga PRT 90535
+2928 Warszawa POL 1615369
+2931 Wroclaw POL 636765
+2974 Paris FRA 2125246
+3048 Stockholm SWE 750348
+3051 Uppsala SWE 189569
+3068 Berlin DEU 3386667
+3087 Bonn DEU 301048
+3242 Lahti FIN 96921
+3580 Moscow RUS 8389200
+3581 St Petersburg RUS 4694000
DROP DATABASE world;
set session optimizer_switch='index_merge_sort_intersection=default';
diff --git a/mysql-test/main/range_vs_index_merge.test b/mysql-test/main/range_vs_index_merge.test
index 6517beab0be..14d75b88bfa 100644
--- a/mysql-test/main/range_vs_index_merge.test
+++ b/mysql-test/main/range_vs_index_merge.test
@@ -714,6 +714,7 @@ SELECT * FROM City
ORDER BY Population LIMIT 5;
FLUSH STATUS;
+--sorted_result
SELECT * FROM City
WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H'))
AND (Population >= 100000 AND Population < 120000)
@@ -1174,9 +1175,9 @@ SELECT * FROM t1,t2,t3
DROP TABLE t1,t2,t3;
-#
-# LP bug #823301: index merge sort union with possible index scan
-#
+--echo #
+--echo # LP bug #823301: index merge sort union with possible index scan
+--echo #
CREATE TABLE t1 (
a int, b int, c int, d int,
@@ -1192,12 +1193,14 @@ SET SESSION optimizer_switch='index_merge_sort_union=off';
EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
+--sorted_result
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
SET SESSION optimizer_switch='index_merge_sort_union=on';
EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
+--sorted_result
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
SET SESSION optimizer_switch=DEFAULT;
@@ -1320,12 +1323,11 @@ where
Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
Country='ITA' AND Name IN ('Napoli', 'Venezia');
-eval $q;
eval explain $q;
-
+--sorted_result
+eval $q;
DROP DATABASE world;
#the following command must be the last one in the file
set session optimizer_switch='index_merge_sort_intersection=default';
-
diff --git a/mysql-test/main/range_vs_index_merge_innodb.result b/mysql-test/main/range_vs_index_merge_innodb.result
index de345f66161..8e0bf58fbc3 100644
--- a/mysql-test/main/range_vs_index_merge_innodb.result
+++ b/mysql-test/main/range_vs_index_merge_innodb.result
@@ -365,7 +365,7 @@ WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 900 AND 1500) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 105000)));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 39,3,4 NULL 212 Using sort_union(Name,Country,Population); Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 39,3,4 NULL 683 Using sort_union(Name,Country,PRIMARY); Using where
EXPLAIN
SELECT * FROM City
WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
@@ -620,7 +620,7 @@ WHERE ((Population > 101000 AND Population < 102000) AND
((ID BETWEEN 3400 AND 3800) AND
(Country < 'AGO' OR Name LIKE 'Pa%'));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,Population 3,39,4 NULL 115 Using sort_union(Country,Name,Population); Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Population,PRIMARY 4,4 NULL 440 Using sort_union(Population,PRIMARY); Using where
EXPLAIN
SELECT * FROM City
WHERE ((Population > 101000 AND Population < 110000) AND
@@ -1331,11 +1331,11 @@ WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H'))
AND (Population >= 100000 AND Population < 120000)
ORDER BY Population LIMIT 5;
ID Name Country Population
+3792 Tartu EST 101246
+518 Basildon GBR 100924
519 Worthing GBR 100000
638 al-Arish EGY 100447
-518 Basildon GBR 100924
707 Marbella ESP 101144
-3792 Tartu EST 101246
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
@@ -1756,6 +1756,9 @@ SELECT * FROM t1,t2,t3
WHERE (t2.f3 = 1 OR t3.f1=t2.f1) AND t3.f1 <> t2.f2 AND t3.f2 = t2.f4;
f1 f1 f2 f3 f4 f1 f2
DROP TABLE t1,t2,t3;
+#
+# LP bug #823301: index merge sort union with possible index scan
+#
CREATE TABLE t1 (
a int, b int, c int, d int,
PRIMARY KEY(b), INDEX idx1(d), INDEX idx2(d,b,c)
@@ -1772,7 +1775,7 @@ EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL 9 Using where
+1 SIMPLE t1 range PRIMARY,idx1,idx2 idx1 5 NULL 5 Using index condition
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
a b c d
@@ -1786,7 +1789,7 @@ EXPLAIN
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL 9 Using where
+1 SIMPLE t1 range PRIMARY,idx1,idx2 idx1 5 NULL 5 Using index condition
SELECT * FROM t1
WHERE t1.b>7 AND t1.d>1 AND t1.d<>8 OR t1.d>=7 AND t1.d<8 OR t1.d>7;
a b c d
@@ -1900,7 +1903,7 @@ INDEX (Percentage)
DROP INDEX Country ON City;
CREATE INDEX CountryName ON City(Country,Name);
CREATE INDEX Name ON City(Name);
-select * from City
+explain select * from City
where
Country='FIN' AND Name IN ('Lahti','Imatra') OR
Country='RUS' AND Name IN ('St Petersburg', 'Moscow') OR
@@ -1912,26 +1915,9 @@ Country='FRA' AND Name IN ('Paris', 'Marcel') OR
Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR
Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
Country='ITA' AND Name IN ('Napoli', 'Venezia');
-ID Name Country Population
-175 Antwerpen BEL 446525
-2808 Bergen NOR 230948
-3068 Berlin DEU 3386667
-3087 Bonn DEU 301048
-2918 Braga PRT 90535
-176 Gent BEL 224180
-3242 Lahti FIN 96921
-3580 Moscow RUS 8389200
-1466 Napoli ITA 1002619
-2807 Oslo NOR 508726
-2974 Paris FRA 2125246
-2915 Porto PRT 273060
-3581 St Petersburg RUS 4694000
-3048 Stockholm SWE 750348
-3051 Uppsala SWE 189569
-1474 Venezia ITA 277305
-2928 Warszawa POL 1615369
-2931 Wroclaw POL 636765
-explain select * from City
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range CountryName,Name Name 35 NULL 20 Using index condition; Using where
+select * from City
where
Country='FIN' AND Name IN ('Lahti','Imatra') OR
Country='RUS' AND Name IN ('St Petersburg', 'Moscow') OR
@@ -1943,8 +1929,25 @@ Country='FRA' AND Name IN ('Paris', 'Marcel') OR
Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR
Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
Country='ITA' AND Name IN ('Napoli', 'Venezia');
-id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City range CountryName,Name Name 35 NULL 20 Using index condition; Using where
+ID Name Country Population
+1466 Napoli ITA 1002619
+1474 Venezia ITA 277305
+175 Antwerpen BEL 446525
+176 Gent BEL 224180
+2807 Oslo NOR 508726
+2808 Bergen NOR 230948
+2915 Porto PRT 273060
+2918 Braga PRT 90535
+2928 Warszawa POL 1615369
+2931 Wroclaw POL 636765
+2974 Paris FRA 2125246
+3048 Stockholm SWE 750348
+3051 Uppsala SWE 189569
+3068 Berlin DEU 3386667
+3087 Bonn DEU 301048
+3242 Lahti FIN 96921
+3580 Moscow RUS 8389200
+3581 St Petersburg RUS 4694000
DROP DATABASE world;
set session optimizer_switch='index_merge_sort_intersection=default';
set global innodb_stats_persistent= @innodb_stats_persistent_save;
diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result
index b68d9891bf1..48a01b31e64 100644
--- a/mysql-test/main/rowid_filter.result
+++ b/mysql-test/main/rowid_filter.result
@@ -242,7 +242,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_shipDATE"],
"rows": 509,
- "filtered": 100,
+ "filtered": 11.69025803,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
}
@@ -254,7 +254,7 @@ set statement optimizer_switch='rowid_filter=off' for ANALYZE SELECT l_orderkey,
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 100.00 11.76 Using index condition; Using where
+1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_orderkey, l_linenumber, l_shipdate, l_quantity FROM lineitem
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
@@ -281,7 +281,7 @@ ANALYZE
"r_rows": 510,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 11.69025803,
"r_filtered": 11.76470588,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
@@ -647,8 +647,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -661,21 +661,8 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "rows": 139,
- "filtered": 100,
- "index_condition": "orders.o_totalprice between 180000 and 230000"
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -683,21 +670,43 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_orderkey",
+ "key": "i_l_shipdate",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
+ "used_key_parts": ["l_shipDATE"],
"rowid_filter": {
"range": {
- "key": "i_l_shipdate",
- "used_key_parts": ["l_shipDATE"]
+ "key": "i_l_quantity",
+ "used_key_parts": ["l_quantity"]
},
- "rows": 509,
- "selectivity_pct": 8.476269775
+ "rows": 702,
+ "selectivity_pct": 11.69025812
},
- "rows": 4,
- "filtered": 0.990897834,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "rows": 509,
+ "filtered": 11.69025803,
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_o_totalprice",
+ "used_key_parts": ["o_totalprice"]
+ },
+ "rows": 139,
+ "selectivity_pct": 9.266666667
+ },
+ "rows": 1,
+ "filtered": 9.266666412,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -709,8 +718,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.54 (8%) 0.99 20.51 Using where; Using rowid filter
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) 60.00 (11%) 11.69 100.00 Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) 0.27 (25%) 9.27 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -728,58 +737,72 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "orders",
+ "table_name": "lineitem",
"access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity",
+ "i_l_quantity"
+ ],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_quantity",
+ "used_key_parts": ["l_quantity"]
+ },
+ "rows": 702,
+ "selectivity_pct": 11.69025812,
+ "r_rows": 605,
+ "r_lookups": 510,
+ "r_selectivity_pct": 11.76470588,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
- "rows": 139,
- "r_rows": 144,
+ "rows": 509,
+ "r_rows": 60,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 11.69025803,
"r_filtered": 100,
- "index_condition": "orders.o_totalprice between 180000 and 230000"
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
}
},
{
"table": {
- "table_name": "lineitem",
- "access_type": "ref",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity",
- "i_l_quantity"
- ],
- "key": "i_l_orderkey",
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_l_shipdate",
- "used_key_parts": ["l_shipDATE"]
+ "key": "i_o_totalprice",
+ "used_key_parts": ["o_totalprice"]
},
- "rows": 509,
- "selectivity_pct": 8.476269775,
- "r_rows": 510,
- "r_lookups": 954,
- "r_selectivity_pct": 8.176100629,
+ "rows": 139,
+ "selectivity_pct": 9.266666667,
+ "r_rows": 144,
+ "r_lookups": 59,
+ "r_selectivity_pct": 25.42372881,
"r_buffer_size": "REPLACED",
"r_filling_time_ms": "REPLACED"
},
- "r_loops": 144,
- "rows": 4,
- "r_rows": 0.541666667,
+ "r_loops": 60,
+ "rows": 1,
+ "r_rows": 0.266666667,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 0.990897834,
- "r_filtered": 20.51282051,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "filtered": 9.266666412,
+ "r_filtered": 100,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -813,8 +836,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 Using index condition; Using where
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -827,21 +850,8 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "rows": 139,
- "filtered": 100,
- "index_condition": "orders.o_totalprice between 180000 and 230000"
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -849,13 +859,27 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_orderkey",
+ "key": "i_l_shipdate",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "rows": 4,
- "filtered": 0.990897834,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "used_key_parts": ["l_shipDATE"],
+ "rows": 509,
+ "filtered": 11.69025803,
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "rows": 1,
+ "filtered": 9.266666412,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -867,8 +891,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.62 0.99 1.68 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.27 26.67 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -886,26 +910,8 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "r_loops": 1,
- "rows": 139,
- "r_rows": 144,
- "r_table_time_ms": "REPLACED",
- "r_other_time_ms": "REPLACED",
- "filtered": 100,
- "r_filtered": 100,
- "index_condition": "orders.o_totalprice between 180000 and 230000"
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -913,18 +919,37 @@ ANALYZE
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_orderkey",
+ "key": "i_l_shipdate",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "r_loops": 144,
- "rows": 4,
- "r_rows": 6.625,
+ "used_key_parts": ["l_shipDATE"],
+ "r_loops": 1,
+ "rows": 509,
+ "r_rows": 510,
+ "r_table_time_ms": "REPLACED",
+ "r_other_time_ms": "REPLACED",
+ "filtered": 11.69025803,
+ "r_filtered": 11.76470588,
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "r_loops": 60,
+ "rows": 1,
+ "r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 0.990897834,
- "r_filtered": 1.677148847,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "filtered": 9.266666412,
+ "r_filtered": 26.66666667,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -1341,7 +1366,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 100,
+ "filtered": 0.566194832,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1370,7 +1395,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 0.57 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1407,7 +1432,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1478,7 +1503,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 100,
+ "filtered": 0.566194832,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1507,7 +1532,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 0.57 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1544,7 +1569,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1595,7 +1620,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1616,7 +1641,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 39,
- "filtered": 100,
+ "filtered": 3.200000048,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1631,7 +1656,7 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -1658,8 +1683,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1689,7 +1714,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 3.200000048,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1705,7 +1730,7 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -1754,7 +1779,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1775,7 +1800,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 39,
- "filtered": 100,
+ "filtered": 3.200000048,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1790,7 +1815,7 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -1809,8 +1834,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1840,7 +1865,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 3.200000048,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1856,7 +1881,7 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -1895,7 +1920,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1936,18 +1961,10 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
- "rowid_filter": {
- "range": {
- "key": "i_l_shipdate",
- "used_key_parts": ["l_shipDATE"]
- },
- "rows": 183,
- "selectivity_pct": 3.04746045
- },
"rows": 4,
"filtered": "REPLACED",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
@@ -1964,7 +1981,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 # 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) # 100.00 Using where; Using rowid filter
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -2015,30 +2032,17 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
- "rowid_filter": {
- "range": {
- "key": "i_l_shipdate",
- "used_key_parts": ["l_shipDATE"]
- },
- "rows": 183,
- "selectivity_pct": 3.04746045,
- "r_rows": 183,
- "r_lookups": 6,
- "r_selectivity_pct": 66.66666667,
- "r_buffer_size": "REPLACED",
- "r_filling_time_ms": "REPLACED"
- },
"r_loops": 1,
"rows": 4,
- "r_rows": 4,
+ "r_rows": 6,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": "REPLACED",
- "r_filtered": 100,
+ "r_filtered": 66.66666667,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -2064,7 +2068,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -2105,7 +2109,7 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -2125,7 +2129,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 # 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -2176,7 +2180,7 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_orderkey",
+ "key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
@@ -2277,7 +2281,7 @@ EXPLAIN EXTENDED
SELECT * FROM t1 HAVING (7, 9) IN (SELECT t2.i1, t2.i2 FROM t2 WHERE t2.i1 = 3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
-2 SUBQUERY t2 ref i1,i2 i1 5 const 1 100.00 Using index condition; Using where
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` having 0
DROP TABLE t1,t2;
@@ -2324,6 +2328,15 @@ pk1 a1 b1 pk2 a2 b2
EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 )
WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00
+1 PRIMARY t1 ALL a1,b1 NULL NULL NULL 400 2.61 Using where; Using join buffer (flat, BNL join)
+2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition
+Warnings:
+Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2
+set @@optimizer_where_cost=0.0356*4;
+EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 )
+WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 );
+id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where
1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter
2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition
@@ -2392,6 +2405,7 @@ EXPLAIN
]
}
}
+set @@optimizer_where_cost=default;
DROP TABLE t1,t2;
#
# MDEV-21794: Optimizer flag rowid_filter leads to long query
@@ -2436,87 +2450,16 @@ drop table t10, t11, t1;
set @save_optimizer_switch= @@optimizer_switch;
SET @@optimizer_switch="index_merge_sort_union=OFF";
CREATE TABLE t1 (a INT, b INT, INDEX(a), INDEX(b));
-INSERT INTO t1 VALUES (0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4);
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-ANALYZE table t1 PERSISTENT FOR ALL;
-Table Op Msg_type Msg_text
-test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze status OK
+INSERT INTO t1 VALUES (0,0),(0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4),(3,3),(3,4),(3,5),(8,8),(8,9),(1,0),(2,0),(0,0),(0,0);
explain
SELECT * FROM t1 WHERE a > 0 AND b=0;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 77 (34%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t1 ref|filter a,b b|a 5|5 const 7 (47%) Using where; Using rowid filter
SELECT * FROM t1 WHERE a > 0 AND b=0;
a b
1 0
1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
+2 0
drop table t1;
SET @@optimizer_switch=@save_optimizer_switch;
#
@@ -2579,7 +2522,7 @@ ANALYZE
"r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 49.20000076,
"r_filtered": 100,
"index_condition": "t1.nm like '500%'",
"attached_condition": "t1.fl2 = 0"
@@ -2632,7 +2575,7 @@ ANALYZE
"r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 49.20000076,
"r_filtered": 100,
"index_condition": "t1.nm like '500%'",
"attached_condition": "t1.fl2 = 0"
@@ -2819,13 +2762,26 @@ ANALYZE
"key": "idx1",
"key_length": "256",
"used_key_parts": ["nm"],
+ "rowid_filter": {
+ "range": {
+ "key": "idx2",
+ "used_key_parts": ["fl2"]
+ },
+ "rows": 863,
+ "selectivity_pct": 8.63,
+ "r_rows": 1000,
+ "r_lookups": 44,
+ "r_selectivity_pct": 0,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 44,
- "r_rows": 44,
+ "r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
- "r_filtered": 0,
+ "filtered": 8.630000114,
+ "r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
}
@@ -2872,12 +2828,25 @@ ANALYZE
"key": "idx1",
"key_length": "256",
"used_key_parts": ["nm"],
+ "rowid_filter": {
+ "range": {
+ "key": "idx2",
+ "used_key_parts": ["fl2"]
+ },
+ "rows": 853,
+ "selectivity_pct": 8.53,
+ "r_rows": 987,
+ "r_lookups": 0,
+ "r_selectivity_pct": 0,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 44,
"r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 8.529999733,
"r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
@@ -2927,8 +2896,8 @@ pk a b c
7 5 k 5
explain SELECT * FROM t1 JOIN t2 WHERE a = c AND pk BETWEEN 4 AND 7 AND a BETWEEN 2 AND 12 AND b != 'foo';
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 ref|filter PRIMARY,a,a_2 a|PRIMARY 5|4 test.t2.c 3 (4%) Using where; Using rowid filter
+1 SIMPLE t1 range|filter PRIMARY,a,a_2 PRIMARY|a 4|5 NULL 4 (11%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
SET optimizer_switch='rowid_filter=off';
SELECT * FROM t1 JOIN t2 WHERE a = c AND pk BETWEEN 4 AND 7 AND a BETWEEN 2 AND 12 AND b != 'foo';
pk a b c
diff --git a/mysql-test/main/rowid_filter.test b/mysql-test/main/rowid_filter.test
index 3718ba051bd..519723b4f29 100644
--- a/mysql-test/main/rowid_filter.test
+++ b/mysql-test/main/rowid_filter.test
@@ -361,7 +361,10 @@ SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 )
eval $q;
eval EXPLAIN EXTENDED $q;
+set @@optimizer_where_cost=0.0356*4;
+eval EXPLAIN EXTENDED $q;
eval EXPLAIN FORMAT=JSON $q;
+set @@optimizer_where_cost=default;
DROP TABLE t1,t2;
@@ -410,16 +413,7 @@ drop table t10, t11, t1;
set @save_optimizer_switch= @@optimizer_switch;
SET @@optimizer_switch="index_merge_sort_union=OFF";
CREATE TABLE t1 (a INT, b INT, INDEX(a), INDEX(b));
-INSERT INTO t1 VALUES (0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4);
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-
-ANALYZE table t1 PERSISTENT FOR ALL;
-
+INSERT INTO t1 VALUES (0,0),(0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4),(3,3),(3,4),(3,5),(8,8),(8,9),(1,0),(2,0),(0,0),(0,0);
explain
SELECT * FROM t1 WHERE a > 0 AND b=0;
SELECT * FROM t1 WHERE a > 0 AND b=0;
diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result
index d4507d224d0..56a7061ddf7 100644
--- a/mysql-test/main/rowid_filter_innodb.result
+++ b/mysql-test/main/rowid_filter_innodb.result
@@ -362,8 +362,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using where; Using index
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -375,35 +375,35 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "rows": 71,
- "filtered": 100,
- "attached_condition": "orders.o_totalprice between 200000 and 230000",
- "using_index": true
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
"i_l_orderkey",
"i_l_orderkey_quantity"
],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
+ "rows": 98,
+ "filtered": 100,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "rows": 4,
- "filtered": 1.633319736,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "rows": 1,
+ "filtered": 4.733333111,
+ "attached_condition": "orders.o_totalprice between 200000 and 230000"
}
}
]
@@ -414,8 +414,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 71.00 100.00 100.00 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 1.63 2.31 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using where; Using index
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 4.73 11.22 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -432,45 +432,45 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "orders",
+ "table_name": "lineitem",
"access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity"
+ ],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
"r_loops": 1,
- "rows": 71,
- "r_rows": 71,
+ "rows": 98,
+ "r_rows": 98,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100,
- "attached_condition": "orders.o_totalprice between 200000 and 230000",
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'",
"using_index": true
}
},
{
"table": {
- "table_name": "lineitem",
- "access_type": "ref",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity"
- ],
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "r_loops": 71,
- "rows": 4,
- "r_rows": 6.704225352,
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "r_loops": 98,
+ "rows": 1,
+ "r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 1.633319736,
- "r_filtered": 2.31092437,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
+ "filtered": 4.733333111,
+ "r_filtered": 11.2244898,
+ "attached_condition": "orders.o_totalprice between 200000 and 230000"
}
}
]
@@ -497,8 +497,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using where; Using index
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -510,35 +510,35 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "rows": 71,
- "filtered": 100,
- "attached_condition": "orders.o_totalprice between 200000 and 230000",
- "using_index": true
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
"i_l_orderkey",
"i_l_orderkey_quantity"
],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
+ "rows": 98,
+ "filtered": 100,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "rows": 4,
- "filtered": 1.633319736,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "rows": 1,
+ "filtered": 4.733333111,
+ "attached_condition": "orders.o_totalprice between 200000 and 230000"
}
}
]
@@ -549,8 +549,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 71.00 100.00 100.00 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 1.63 2.31 Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using where; Using index
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 4.73 11.22 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -567,45 +567,45 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "orders",
+ "table_name": "lineitem",
"access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity"
+ ],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
"r_loops": 1,
- "rows": 71,
- "r_rows": 71,
+ "rows": 98,
+ "r_rows": 98,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100,
- "attached_condition": "orders.o_totalprice between 200000 and 230000",
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'",
"using_index": true
}
},
{
"table": {
- "table_name": "lineitem",
- "access_type": "ref",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity"
- ],
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "r_loops": 71,
- "rows": 4,
- "r_rows": 6.704225352,
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "r_loops": 98,
+ "rows": 1,
+ "r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 1.633319736,
- "r_filtered": 2.31092437,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
+ "filtered": 4.733333111,
+ "r_filtered": 11.2244898,
+ "attached_condition": "orders.o_totalprice between 200000 and 230000"
}
}
]
@@ -633,8 +633,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -647,22 +647,8 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
- "rows": 144,
- "filtered": 100,
- "attached_condition": "orders.o_totalprice between 180000 and 230000",
- "using_index": true
- }
- },
- {
- "table": {
"table_name": "lineitem",
- "access_type": "ref",
+ "access_type": "range",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -670,13 +656,35 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_quantity",
+ "used_key_parts": ["l_quantity"]
+ },
+ "rows": 605,
+ "selectivity_pct": 10.07493755
+ },
+ "rows": 510,
+ "filtered": 10.07493782,
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
+ }
+ },
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "rows": 4,
- "filtered": 0.856362581,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "rows": 1,
+ "filtered": 9.600000381,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -688,8 +696,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 144.00 100.00 100.00 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.62 0.86 1.68 Using where
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) 60.00 (11%) 10.07 100.00 Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.60 26.67 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -707,46 +715,59 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "orders",
+ "table_name": "lineitem",
"access_type": "range",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "i_o_totalprice",
- "key_length": "9",
- "used_key_parts": ["o_totalprice"],
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity",
+ "i_l_quantity"
+ ],
+ "key": "i_l_shipdate",
+ "key_length": "4",
+ "used_key_parts": ["l_shipDATE"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_quantity",
+ "used_key_parts": ["l_quantity"]
+ },
+ "rows": 605,
+ "selectivity_pct": 10.07493755,
+ "r_rows": 605,
+ "r_lookups": 510,
+ "r_selectivity_pct": 11.76470588,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
- "rows": 144,
- "r_rows": 144,
+ "rows": 510,
+ "r_rows": 60,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 10.07493782,
"r_filtered": 100,
- "attached_condition": "orders.o_totalprice between 180000 and 230000",
- "using_index": true
+ "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
+ "attached_condition": "lineitem.l_quantity > 45"
}
},
{
"table": {
- "table_name": "lineitem",
- "access_type": "ref",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity",
- "i_l_quantity"
- ],
+ "table_name": "orders",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
"key": "PRIMARY",
"key_length": "4",
- "used_key_parts": ["l_orderkey"],
- "ref": ["dbt3_s001.orders.o_orderkey"],
- "r_loops": 144,
- "rows": 4,
- "r_rows": 6.625,
+ "used_key_parts": ["o_orderkey"],
+ "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "r_loops": 60,
+ "rows": 1,
+ "r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 0.856362581,
- "r_filtered": 1.677148847,
- "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
+ "filtered": 9.600000381,
+ "r_filtered": 26.66666667,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000"
}
}
]
@@ -822,7 +843,7 @@ EXPLAIN
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
"rows": 4,
- "filtered": 0.856362581,
+ "filtered": 0.855656624,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
@@ -891,7 +912,7 @@ ANALYZE
"r_rows": 6.625,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 0.856362581,
+ "filtered": 0.855656624,
"r_filtered": 1.677148847,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
@@ -974,7 +995,7 @@ EXPLAIN
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
"rows": 4,
- "filtered": 8.499929428,
+ "filtered": 8.492922783,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
}
}
@@ -987,7 +1008,7 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 71.00 100.00 100.00 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 8.50 7.77 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 8.49 7.77 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -1040,7 +1061,7 @@ ANALYZE
"r_rows": 6.704225352,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.499929428,
+ "filtered": 8.492922783,
"r_filtered": 7.773109244,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
}
@@ -1135,7 +1156,7 @@ EXPLAIN
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
"rows": 4,
- "filtered": 8.499929428,
+ "filtered": 8.492922783,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
}
}
@@ -1148,7 +1169,7 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 71 71.00 100.00 100.00 Using where; Using index
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 8.50 7.77 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.70 8.49 7.77 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -1201,7 +1222,7 @@ ANALYZE
"r_rows": 6.704225352,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.499929428,
+ "filtered": 8.492922783,
"r_filtered": 7.773109244,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
}
@@ -1588,7 +1609,7 @@ EXPLAIN
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
"rows": 4,
- "filtered": 3.04997468,
+ "filtered": 3.047460556,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -1658,7 +1679,7 @@ ANALYZE
"r_rows": 6,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.04997468,
+ "filtered": 3.047460556,
"r_filtered": 66.66666667,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
@@ -1726,7 +1747,7 @@ EXPLAIN
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
"rows": 4,
- "filtered": 3.04997468,
+ "filtered": 3.047460556,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -1796,7 +1817,7 @@ ANALYZE
"r_rows": 6,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.04997468,
+ "filtered": 3.047460556,
"r_filtered": 66.66666667,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
@@ -2187,7 +2208,7 @@ EXPLAIN EXTENDED
SELECT * FROM t1 HAVING (7, 9) IN (SELECT t2.i1, t2.i2 FROM t2 WHERE t2.i1 = 3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
-2 SUBQUERY t2 ref i1,i2 i1 5 const 1 10.00 Using index condition; Using where
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` having 0
DROP TABLE t1,t2;
@@ -2234,6 +2255,15 @@ pk1 a1 b1 pk2 a2 b2
EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 )
WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00
+1 PRIMARY t1 ALL a1,b1 NULL NULL NULL 400 2.61 Using where; Using join buffer (flat, BNL join)
+2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition
+Warnings:
+Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2
+set @@optimizer_where_cost=0.0356*4;
+EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 )
+WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 );
+id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where
1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter
2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition
@@ -2264,9 +2294,17 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["a1"],
"ref": ["test.t2.a2"],
- "rows": 1,
- "filtered": 87,
- "attached_condition": "t1.b1 <= (subquery#2)"
+ "rowid_filter": {
+ "range": {
+ "key": "b1",
+ "used_key_parts": ["b1"]
+ },
+ "rows": 115,
+ "selectivity_pct": 28.75
+ },
+ "rows": 36,
+ "filtered": 28.75,
+ "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2"
}
}
],
@@ -2294,6 +2332,7 @@ EXPLAIN
]
}
}
+set @@optimizer_where_cost=default;
DROP TABLE t1,t2;
#
# MDEV-21794: Optimizer flag rowid_filter leads to long query
@@ -2330,7 +2369,7 @@ explain
select * from t1
where el_index like '10%' and (el_index_60 like '10%' or el_index_60 like '20%');
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL el_index,el_index_60 NULL NULL NULL 10000 Using where
+1 SIMPLE t1 range el_index,el_index_60 el_index 62 NULL 1000 Using where
drop table t10, t11, t1;
#
# MDEV-22160: SIGSEGV in st_join_table::save_explain_data on SELECT
@@ -2338,87 +2377,16 @@ drop table t10, t11, t1;
set @save_optimizer_switch= @@optimizer_switch;
SET @@optimizer_switch="index_merge_sort_union=OFF";
CREATE TABLE t1 (a INT, b INT, INDEX(a), INDEX(b));
-INSERT INTO t1 VALUES (0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4);
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-INSERT INTO t1 SELECT * FROM t1;
-ANALYZE table t1 PERSISTENT FOR ALL;
-Table Op Msg_type Msg_text
-test.t1 analyze status Engine-independent statistics collected
-test.t1 analyze status OK
+INSERT INTO t1 VALUES (0,0),(0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4),(3,3),(3,4),(3,5),(8,8),(8,9),(1,0),(2,0),(0,0),(0,0);
explain
SELECT * FROM t1 WHERE a > 0 AND b=0;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 64 (29%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t1 ref|filter a,b b|a 5|5 const 7 (47%) Using where; Using rowid filter
SELECT * FROM t1 WHERE a > 0 AND b=0;
a b
1 0
1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
+2 0
drop table t1;
SET @@optimizer_switch=@save_optimizer_switch;
#
@@ -2481,7 +2449,7 @@ ANALYZE
"r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 49.20000076,
"r_filtered": 100,
"index_condition": "t1.nm like '500%'",
"attached_condition": "t1.fl2 = 0"
@@ -2534,7 +2502,7 @@ ANALYZE
"r_rows": 1,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 49.20000076,
"r_filtered": 100,
"index_condition": "t1.nm like '500%'",
"attached_condition": "t1.fl2 = 0"
@@ -2721,13 +2689,26 @@ ANALYZE
"key": "idx1",
"key_length": "256",
"used_key_parts": ["nm"],
+ "rowid_filter": {
+ "range": {
+ "key": "idx2",
+ "used_key_parts": ["fl2"]
+ },
+ "rows": 863,
+ "selectivity_pct": 8.63,
+ "r_rows": 1000,
+ "r_lookups": 44,
+ "r_selectivity_pct": 0,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 44,
- "r_rows": 44,
+ "r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
- "r_filtered": 0,
+ "filtered": 8.630000114,
+ "r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
}
@@ -2774,12 +2755,25 @@ ANALYZE
"key": "idx1",
"key_length": "256",
"used_key_parts": ["nm"],
+ "rowid_filter": {
+ "range": {
+ "key": "idx2",
+ "used_key_parts": ["fl2"]
+ },
+ "rows": 853,
+ "selectivity_pct": 8.53,
+ "r_rows": 987,
+ "r_lookups": 0,
+ "r_selectivity_pct": 0,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 44,
"r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 100,
+ "filtered": 8.529999733,
"r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
@@ -2879,8 +2873,8 @@ union
( select * from t1
where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a')));
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where
-2 UNION t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where
+1 PRIMARY t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter
+2 UNION t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
explain format=json ( select * from t1
where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a')))
@@ -2901,28 +2895,24 @@ EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "index_merge",
+ "access_type": "ref",
"possible_keys": ["f1", "f2"],
- "key_length": "13,33",
- "index_merge": {
- "intersect": [
- {
- "range": {
- "key": "f1",
- "used_key_parts": ["f1"]
- }
- },
- {
- "range": {
- "key": "f2",
- "used_key_parts": ["f2"]
- }
- }
- ]
+ "key": "f1",
+ "key_length": "13",
+ "used_key_parts": ["f1"],
+ "ref": ["const"],
+ "rowid_filter": {
+ "range": {
+ "key": "f1",
+ "used_key_parts": ["f1"]
+ },
+ "rows": 1,
+ "selectivity_pct": 1.587301587
},
"rows": 1,
"filtered": 1.587301612,
- "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
+ "index_condition": "t1.f1 is null",
+ "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
}
}
]
@@ -2936,28 +2926,24 @@ EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "index_merge",
+ "access_type": "ref",
"possible_keys": ["f1", "f2"],
- "key_length": "13,33",
- "index_merge": {
- "intersect": [
- {
- "range": {
- "key": "f1",
- "used_key_parts": ["f1"]
- }
- },
- {
- "range": {
- "key": "f2",
- "used_key_parts": ["f2"]
- }
- }
- ]
+ "key": "f1",
+ "key_length": "13",
+ "used_key_parts": ["f1"],
+ "ref": ["const"],
+ "rowid_filter": {
+ "range": {
+ "key": "f1",
+ "used_key_parts": ["f1"]
+ },
+ "rows": 1,
+ "selectivity_pct": 1.587301587
},
"rows": 1,
"filtered": 1.587301612,
- "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
+ "index_condition": "t1.f1 is null",
+ "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
}
}
]
@@ -2983,8 +2969,8 @@ id y x
1 2 1
explain extended select * from t1 join t2 on t1.id = t2.x where t2.y = 2 and t1.id = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 #
-1 SIMPLE t2 index_merge x,y y,x 5,5 NULL 1 # Using intersect(y,x); Using where; Using index
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const # #
+1 SIMPLE t2 ref|filter x,y y|x 5|5 const # # Using where; Using rowid filter
Warnings:
Note 1003 select 1 AS `id`,`test`.`t2`.`y` AS `y`,`test`.`t2`.`x` AS `x` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`y` = 2 and `test`.`t2`.`x` = 1
drop table t1, t2;
@@ -3005,7 +2991,7 @@ count(*)
5
explain extended select count(*) from t1 where a between 21 and 30 and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range b,a a 5 NULL 33 5.90 Using index condition; Using where
+1 SIMPLE t1 ref b,a b 5 const 24 9.60 Using where
Warnings:
Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` between 21 and 30
select * from t1 where a between 21 and 30 and b=2;
@@ -3058,12 +3044,12 @@ Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN EXTENDED
-SELECT a FROM t1 WHERE c < 'k' AND b > 't' ORDER BY a;
+SELECT a FROM t1 WHERE c < 'e' AND b > 't' ORDER BY a;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range|filter b,c b|c 13|1027 NULL 5 (42%) 41.67 Using index condition; Using where; Using filesort; Using rowid filter
+1 SIMPLE t1 range|filter b,c b|c 13|1027 NULL 5 (21%) 20.83 Using index condition; Using where; Using filesort; Using rowid filter
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`c` < 'k' and `test`.`t1`.`b` > 't' order by `test`.`t1`.`a`
-SELECT a FROM t1 WHERE c < 'k' AND b > 't' ORDER BY a;
+Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`c` < 'e' and `test`.`t1`.`b` > 't' order by `test`.`t1`.`a`
+SELECT a FROM t1 WHERE c < 'e' AND b > 't' ORDER BY a;
a
1
5
@@ -3106,11 +3092,11 @@ t1.id2 = t1.id);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1 100.00 Using where
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 10 100.00 Using where
-3 DEPENDENT SUBQUERY t2 range PRIMARY,col_date_key,ch2,id2 ch2 4 NULL 2 100.00 Using where; Using index
-3 DEPENDENT SUBQUERY bt1 ALL NULL NULL NULL NULL 10 100.00 Using where; Using join buffer (flat, BNL join)
+3 MATERIALIZED t2 range PRIMARY,col_date_key,ch2,id2 ch2 4 NULL 2 100.00 Using where; Using index
+3 MATERIALIZED bt1 ALL NULL NULL NULL NULL 10 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t3.id' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t3` where <in_optimizer>(1,<expr_cache><`test`.`t3`.`id`>(exists(/* select#2 */ select 1 from `test`.`t1` where <expr_cache><`test`.`t3`.`id`>(<in_optimizer>(`test`.`t3`.`id`,<exists>(/* select#3 */ select `test`.`bt1`.`id` from `test`.`t2` join `test`.`t1` `bt1` where `test`.`bt1`.`id` = `test`.`t2`.`pk` and `test`.`t2`.`ch2` <= 'g' and <cache>(`test`.`t3`.`id`) = `test`.`bt1`.`id`))) or `test`.`t1`.`id2` = `test`.`t1`.`id` limit 1)))
+Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t3` where <in_optimizer>(1,<expr_cache><`test`.`t3`.`id`>(exists(/* select#2 */ select 1 from `test`.`t1` where <expr_cache><`test`.`t3`.`id`>(<in_optimizer>(`test`.`t3`.`id`,`test`.`t3`.`id` in ( <materialize> (/* select#3 */ select `test`.`bt1`.`id` from `test`.`t2` join `test`.`t1` `bt1` where `test`.`bt1`.`id` = `test`.`t2`.`pk` and `test`.`t2`.`ch2` <= 'g' ), <primary_index_lookup>(`test`.`t3`.`id` in <temporary table> on distinct_key where `test`.`t3`.`id` = `<subquery3>`.`id`)))) or `test`.`t1`.`id2` = `test`.`t1`.`id` limit 1)))
SELECT 1 FROM t3
WHERE EXISTS ( SELECT 1 FROM t1
WHERE t3.id IN ( SELECT bt1.id FROM t2, t1 AS bt1
@@ -3129,11 +3115,11 @@ t1.id2 = t1.id);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1 100.00 Using where
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 10 100.00 Using where
-3 DEPENDENT SUBQUERY t2 range PRIMARY,col_date_key,ch2,id2 ch2 4 NULL 2 100.00 Using where; Using index
-3 DEPENDENT SUBQUERY bt1 ALL NULL NULL NULL NULL 10 100.00 Using where; Using join buffer (flat, BNL join)
+3 MATERIALIZED t2 range PRIMARY,col_date_key,ch2,id2 ch2 4 NULL 2 100.00 Using where; Using index
+3 MATERIALIZED bt1 ALL NULL NULL NULL NULL 10 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t3.id' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t3` where <in_optimizer>(1,<expr_cache><`test`.`t3`.`id`>(exists(/* select#2 */ select 1 from `test`.`t1` where <expr_cache><`test`.`t3`.`id`>(<in_optimizer>(`test`.`t3`.`id`,<exists>(/* select#3 */ select `test`.`bt1`.`id` from `test`.`t2` join `test`.`t1` `bt1` where `test`.`bt1`.`ch` = `test`.`t2`.`ch2` and `test`.`bt1`.`id` = `test`.`t2`.`pk` and `test`.`t2`.`ch2` <= 'g' and <cache>(`test`.`t3`.`id`) = `test`.`bt1`.`id`))) or `test`.`t1`.`id2` = `test`.`t1`.`id` limit 1)))
+Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t3` where <in_optimizer>(1,<expr_cache><`test`.`t3`.`id`>(exists(/* select#2 */ select 1 from `test`.`t1` where <expr_cache><`test`.`t3`.`id`>(<in_optimizer>(`test`.`t3`.`id`,`test`.`t3`.`id` in ( <materialize> (/* select#3 */ select `test`.`bt1`.`id` from `test`.`t2` join `test`.`t1` `bt1` where `test`.`bt1`.`ch` = `test`.`t2`.`ch2` and `test`.`bt1`.`id` = `test`.`t2`.`pk` and `test`.`t2`.`ch2` <= 'g' ), <primary_index_lookup>(`test`.`t3`.`id` in <temporary table> on distinct_key where `test`.`t3`.`id` = `<subquery3>`.`id`)))) or `test`.`t1`.`id2` = `test`.`t1`.`id` limit 1)))
SELECT 1 FROM t3
WHERE EXISTS ( SELECT 1 FROM t1
WHERE t3.id IN ( SELECT bt1.id FROM t2, t1 AS bt1
@@ -3170,7 +3156,7 @@ test.t1 analyze status OK
explain extended select count(0) from t1
where id=15066 and (match s against ('+"fttest"' in boolean mode));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ref id,s id 5 const 1 100.00 Using where
+1 SIMPLE t1 fulltext id,s s 0 1 1.64 Using where
Warnings:
Note 1003 select count(0) AS `count(0)` from `test`.`t1` where `test`.`t1`.`id` = 15066 and (match `test`.`t1`.`s` against ('+"fttest"' in boolean mode))
select count(0) from t1
@@ -3474,16 +3460,16 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND
timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH)
ORDER BY timestamp DESC;
id domain registrant_name registrant_organization registrant_street1 registrant_street2 registrant_street3 registrant_street4 registrant_street5 registrant_city registrant_postal_code registrant_country registrant_email registrant_telephone administrative_name administrative_organization administrative_street1 administrative_street2 administrative_street3 administrative_street4 administrative_street5 administrative_city administrative_postal_code administrative_country administrative_email administrative_telephone technical_name technical_organization technical_street1 technical_street2 technical_street3 technical_street4 technical_street5 technical_city technical_postal_code technical_country technical_email technical_telephone json timestamp
-80609 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
-80594 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
-80579 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
80551 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80579 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80594 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80609 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
EXPLAIN EXTENDED SELECT * FROM t1
WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND
timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH)
ORDER BY timestamp DESC;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainTimestamp 4 NULL 1 28.57 Using where
+1 SIMPLE t1 ALL ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp NULL NULL NULL 60 22.22 Using where; Using filesort
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_street2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test`.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= <cache>('2017-01-30 08:24:51' + interval -1 month) order by `test`.`t1`.`timestamp` desc
SET optimizer_switch=@save_optimizer_switch;
@@ -3675,7 +3661,7 @@ fi.fh in (6311439873746261694,-397087483897438286,
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index
1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where
-1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 26.09 Using where
+1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where
Warnings:
Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)
set statement optimizer_switch='rowid_filter=off' for select t.id, fi.*
@@ -3732,7 +3718,7 @@ fi.fh in (6311439873746261694,-397087483897438286,
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index
1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where
-1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 26.09 Using where
+1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using rowid filter
Warnings:
Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)
set statement optimizer_switch='rowid_filter=on' for select t.id, fi.*
@@ -3791,7 +3777,7 @@ fi.fh in (6311439873746261694,-397087483897438286,
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index
1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan
-1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 26.09 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan
+1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan
Warnings:
Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)
set statement optimizer_switch='rowid_filter=off' for select t.id, fi.*
@@ -3848,7 +3834,7 @@ fi.fh in (6311439873746261694,-397087483897438286,
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index
1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan
-1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 26.09 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan
+1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan; Using rowid filter
Warnings:
Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)
set statement optimizer_switch='rowid_filter=on' for select t.id, fi.*
@@ -4000,7 +3986,7 @@ ANALYZE
"r_rows": 32,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 26.08628654,
+ "filtered": 14.46428585,
"r_filtered": 100
},
"buffer_type": "incremental",
@@ -4008,7 +3994,7 @@ ANALYZE
"join_type": "BKA",
"mrr_type": "Rowid-ordered scan",
"attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)",
- "r_filtered": 40,
+ "r_filtered": 100,
"r_unpack_time_ms": "REPLACED"
}
}
@@ -4048,6 +4034,16 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
+EXPLAIN EXTENDED SELECT * FROM t1
+WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1
+WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 60 100.00 Using where
+2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 38 (25%) 25.00 Using where; Full scan on NULL key; Using rowid filter
+2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 60 100.00 Using join buffer (flat, BNL join)
+Warnings:
+Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where !<expr_cache><`test`.`t1`.`c1`,`test`.`t1`.`pk`>(<in_optimizer>(`test`.`t1`.`c1`,<exists>(/* select#2 */ select `test`.`t2`.`c1` from `test`.`t2` join `test`.`t1` `a1` where `test`.`t2`.`i1` = `test`.`t1`.`pk` and `test`.`t2`.`i1` between 3 and 5 and trigcond(<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c1`))))
SELECT * FROM t1
WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1
WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5);
@@ -4112,16 +4108,6 @@ pk c1
128 y
129 NULL
133 NULL
-EXPLAIN EXTENDED SELECT * FROM t1
-WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1
-WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 15 100.00 Using where
-2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 6 (33%) 11.11 Using where; Full scan on NULL key; Using rowid filter
-2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 15 100.00 Using join buffer (flat, BNL join)
-Warnings:
-Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where !<expr_cache><`test`.`t1`.`c1`,`test`.`t1`.`pk`>(<in_optimizer>(`test`.`t1`.`c1`,<exists>(/* select#2 */ select `test`.`t2`.`c1` from `test`.`t2` join `test`.`t1` `a1` where `test`.`t2`.`i1` = `test`.`t1`.`pk` and `test`.`t2`.`i1` between 3 and 5 and trigcond(<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c1`))))
DROP TABLE t1,t2;
set global innodb_stats_persistent= @stats.save;
# End of 10.4 tests
diff --git a/mysql-test/main/rowid_filter_innodb.test b/mysql-test/main/rowid_filter_innodb.test
index 339d4e37f67..604f32cd56e 100644
--- a/mysql-test/main/rowid_filter_innodb.test
+++ b/mysql-test/main/rowid_filter_innodb.test
@@ -70,7 +70,7 @@ let $q=
select * from t1 join t2 on t1.id = t2.x where t2.y = 2 and t1.id = 1;
eval $q;
---replace_column 10 #
+--replace_column 9 # 10 #
eval explain extended $q;
drop table t1, t2;
@@ -133,9 +133,9 @@ INSERT INTO t1 VALUES
ANALYZE TABLE t1;
EXPLAIN EXTENDED
-SELECT a FROM t1 WHERE c < 'k' AND b > 't' ORDER BY a;
+SELECT a FROM t1 WHERE c < 'e' AND b > 't' ORDER BY a;
-SELECT a FROM t1 WHERE c < 'k' AND b > 't' ORDER BY a;
+SELECT a FROM t1 WHERE c < 'e' AND b > 't' ORDER BY a;
DROP TABLE t1;
SET GLOBAL innodb_stats_persistent= @stats.save;
@@ -644,8 +644,8 @@ SELECT * FROM t1
WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1
WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5);
-eval $q;
eval EXPLAIN EXTENDED $q;
+eval $q;
DROP TABLE t1,t2;
diff --git a/mysql-test/main/rowid_filter_innodb_debug.result b/mysql-test/main/rowid_filter_innodb_debug.result
index f82b29aa1e6..af800346f75 100644
--- a/mysql-test/main/rowid_filter_innodb_debug.result
+++ b/mysql-test/main/rowid_filter_innodb_debug.result
@@ -2,8 +2,10 @@ set default_storage_engine=innodb;
#
# MDEV-22761 KILL QUERY during rowid_filter, crashes
#
+create table t1(a int);
+insert into t1 select seq from seq_1_to_1000;
create table t2(a int);
-insert into t2 select * from seq_0_to_99;
+insert into t2 select seq from seq_1_to_100;
CREATE TABLE t3 (
key1 int ,
key2 int,
@@ -11,16 +13,11 @@ filler varchar(255),
KEY (key1),
KEY (key2)
);
+insert into t3 select seq,seq, 'filler-data-filler-data' from seq_1_to_2000;
select engine from information_schema.tables
where table_schema=database() and table_name='t3';
engine
InnoDB
-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;
Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected
@@ -30,14 +27,14 @@ test.t3 analyze status OK
explain
select * from t2, t3
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);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 100 Using where
-1 SIMPLE t3 ref|filter key1,key2 key1|key2 5|5 test.t2.a 100 (2%) Using where; Using rowid filter
+1 SIMPLE t3 ref|filter key1,key2 key1|key2 5|5 test.t2.a 1 (0%) Using where; Using rowid filter
set debug_sync='handler_rowid_filter_check SIGNAL at_rowid_filter_check WAIT_FOR go';
select * from t2, t3
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,,;
set debug_sync='now WAIT_FOR at_rowid_filter_check';
kill query $target_id;
@@ -46,5 +43,5 @@ connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
-drop table t2,t3;
+drop table t1,t2,t3;
set default_storage_engine=default;
diff --git a/mysql-test/main/rowid_filter_myisam_debug.result b/mysql-test/main/rowid_filter_myisam_debug.result
index 75a8fad6947..d68714cc303 100644
--- a/mysql-test/main/rowid_filter_myisam_debug.result
+++ b/mysql-test/main/rowid_filter_myisam_debug.result
@@ -1,8 +1,10 @@
#
# MDEV-22761 KILL QUERY during rowid_filter, crashes
#
+create table t1(a int);
+insert into t1 select seq from seq_1_to_1000;
create table t2(a int);
-insert into t2 select * from seq_0_to_99;
+insert into t2 select seq from seq_1_to_100;
CREATE TABLE t3 (
key1 int ,
key2 int,
@@ -10,16 +12,11 @@ filler varchar(255),
KEY (key1),
KEY (key2)
);
+insert into t3 select seq,seq, 'filler-data-filler-data' from seq_1_to_2000;
select engine from information_schema.tables
where table_schema=database() and table_name='t3';
engine
MyISAM
-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;
Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected
@@ -29,14 +26,14 @@ test.t3 analyze status Table is already up to date
explain
select * from t2, t3
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);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 100 Using where
-1 SIMPLE t3 ref|filter key1,key2 key1|key2 5|5 test.t2.a 100 (2%) Using where; Using rowid filter
+1 SIMPLE t3 ref|filter key1,key2 key1|key2 5|5 test.t2.a 1 (0%) Using where; Using rowid filter
set debug_sync='handler_rowid_filter_check SIGNAL at_rowid_filter_check WAIT_FOR go';
select * from t2, t3
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,,;
set debug_sync='now WAIT_FOR at_rowid_filter_check';
kill query $target_id;
@@ -45,4 +42,4 @@ connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
-drop table t2,t3;
+drop table t1,t2,t3;
diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result
index 675601df08c..af65ca169d6 100644
--- a/mysql-test/main/select.result
+++ b/mysql-test/main/select.result
@@ -603,6 +603,31 @@ 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
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
+#
+# Some test with ORDER BY and limit
+#
+explain select count(*) 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
+1 SIMPLE t1 index period period 4 NULL 41810 Using index
+1 SIMPLE t3 ref period period 4 test.t1.period 4181 Using index
+explain select sum(t1.price+t3.price) 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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=0;
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
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
@@ -615,6 +640,10 @@ explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period l
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index period period 4 NULL 1
1 SIMPLE t3 ref period period 4 test.t1.period 4181
+set @@join_cache_level=@save_join_cache_level;
+#
+# Search with a constant table.
+#
select period from t1;
period
9410
@@ -1378,18 +1407,28 @@ 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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999;
+#
+# Test left join optimization
+#
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=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
+1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
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 t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
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 t2 ALL NULL NULL NULL NULL 1199 Using where
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
+set @@join_cache_level=@save_join_cache_level;
+explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
+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 t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (flat, BNL join)
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
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
@@ -1426,6 +1465,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
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
+#
+# Joins with forms.
+#
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr companynr
37 36
@@ -2364,16 +2406,16 @@ insert into t1 values (1,2), (2,2), (3,2), (4,2);
insert into t2 values (1,3), (2,3), (3,4), (4,4);
explain select * from t1 left join t2 on a=c where d in (4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2
select * from t1 left join t2 on a=c where d in (4);
a b c d
3 2 3 4
4 2 4 4
explain select * from t1 left join t2 on a=c where d = 4;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2
select * from t1 left join t2 on a=c where d = 4;
a b c d
3 2 3 4
@@ -3479,7 +3521,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using index condition; Using where
+1 SIMPLE t1 range|filter PRIMARY,b b|PRIMARY 5|4 NULL 3 (90%) Using index condition; Using where; Using rowid filter
1 SIMPLE t2 ref c c 5 test.t1.a 2
DROP TABLE t1, t2;
create table t1 (
@@ -3540,7 +3582,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
+1 SIMPLE t3 ref idx1 idx1 5 const 4
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3640,7 +3682,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si si 5 NULL 2 Using index condition; Using where
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3648,7 +3690,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 2 Using index condition; Using where
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
DROP TABLE t1,t2,t3;
CREATE TABLE t1 ( f1 int primary key, f2 int, f3 int, f4 int, f5 int, f6 int, checked_out int);
CREATE TABLE t2 ( f11 int PRIMARY KEY );
@@ -3725,11 +3767,11 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (6%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|5 const 2 (27%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3739,7 +3781,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (7%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3773,7 +3815,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
+1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4039,7 +4081,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
+1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select.test b/mysql-test/main/select.test
index 2974987a683..95b66d69255 100644
--- a/mysql-test/main/select.test
+++ b/mysql-test/main/select.test
@@ -1461,17 +1461,26 @@ 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;
-#
-# Some test with ORDER BY and limit
-#
+--echo #
+--echo # Some test with ORDER BY and limit
+--echo #
+
+explain select count(*) from t3 as t1,t3 where t1.period=t3.period order by t3.period;
+explain select sum(t1.price+t3.price) 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 t1.period limit 10;
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=0;
+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 t1.period limit 10;
+set @@join_cache_level=@save_join_cache_level;
-#
-# Search with a constant table.
-#
+--echo #
+--echo # Search with a constant table.
+--echo #
select period from t1;
select period from t1 where period=1900;
@@ -1563,12 +1572,17 @@ 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;
delete from t2 where fld1=999999;
-#
-# Test left join optimization
+--echo #
+--echo # Test left join optimization
+--echo #
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=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 and t4.companynr > 0;
+set @@join_cache_level=@save_join_cache_level;
+explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
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 or companynr < 0;
@@ -1582,9 +1596,9 @@ explain select companynr,companyname from t4 left join t2 using (companynr) wher
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 ifnull(companynr,1)>0;
-#
-# Joins with forms.
-#
+--echo #
+--echo # Joins with forms.
+--echo #
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result
index 19970c90c7f..74a0dbd8855 100644
--- a/mysql-test/main/select_jcl6.result
+++ b/mysql-test/main/select_jcl6.result
@@ -614,18 +614,47 @@ 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
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
+#
+# Some test with ORDER BY and limit
+#
+explain select count(*) 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
+1 SIMPLE t1 index period period 4 NULL 41810 Using index
+1 SIMPLE t3 ref period period 4 test.t1.period 4181 Using index
+explain select sum(t1.price+t3.price) 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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
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
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
-1 SIMPLE t3 ref period period 4 test.t1.period 4181 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
-1 SIMPLE t1 ref period period 4 test.t3.period 4181 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
-1 SIMPLE t3 ref period period 4 test.t1.period 4181 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=0;
+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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
+1 SIMPLE t3 ref period period 4 test.t1.period 4181
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 index period period 4 NULL 1
+1 SIMPLE t1 ref period period 4 test.t3.period 4181
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index period period 4 NULL 1
+1 SIMPLE t3 ref period period 4 test.t1.period 4181
+set @@join_cache_level=@save_join_cache_level;
+#
+# Search with a constant table.
+#
select period from t1;
period
9410
@@ -1389,17 +1418,27 @@ 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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999;
+#
+# Test left join optimization
+#
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=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
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
-1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
+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 < 0;
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 t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
+1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
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 t2 ALL NULL NULL NULL NULL 1199 Using where
+set @@join_cache_level=@save_join_cache_level;
+explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
+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 t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
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
@@ -1437,6 +1476,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
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where
1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
+#
+# Joins with forms.
+#
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr companynr
37 36
@@ -2375,16 +2417,16 @@ insert into t1 values (1,2), (2,2), (3,2), (4,2);
insert into t2 values (1,3), (2,3), (3,4), (4,4);
explain select * from t1 left join t2 on a=c where d in (4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
select * from t1 left join t2 on a=c where d in (4);
a b c d
3 2 3 4
4 2 4 4
explain select * from t1 left join t2 on a=c where d = 4;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
select * from t1 left join t2 on a=c where d = 4;
a b c d
3 2 3 4
@@ -3490,7 +3532,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using index condition; Using where; Rowid-ordered scan
+1 SIMPLE t1 range|filter PRIMARY,b b|PRIMARY 5|4 NULL 3 (90%) Using index condition; Using where; Rowid-ordered scan; Using rowid filter
1 SIMPLE t2 ref c c 5 test.t1.a 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
DROP TABLE t1, t2;
create table t1 (
@@ -3551,7 +3593,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
+1 SIMPLE t3 ref idx1 idx1 5 const 4
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3651,7 +3693,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si si 5 NULL 2 Using index condition; Using where; Rowid-ordered scan
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3659,7 +3701,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 2 Using index condition; Using where; Rowid-ordered scan
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
DROP TABLE t1,t2,t3;
CREATE TABLE t1 ( f1 int primary key, f2 int, f3 int, f4 int, f5 int, f6 int, checked_out int);
CREATE TABLE t2 ( f11 int PRIMARY KEY );
@@ -3736,11 +3778,11 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (6%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|5 const 2 (27%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3750,7 +3792,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (7%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3784,7 +3826,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
+1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4050,7 +4092,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
+1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result
index 675601df08c..af65ca169d6 100644
--- a/mysql-test/main/select_pkeycache.result
+++ b/mysql-test/main/select_pkeycache.result
@@ -603,6 +603,31 @@ 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
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
+#
+# Some test with ORDER BY and limit
+#
+explain select count(*) 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
+1 SIMPLE t1 index period period 4 NULL 41810 Using index
+1 SIMPLE t3 ref period period 4 test.t1.period 4181 Using index
+explain select sum(t1.price+t3.price) 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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+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
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort
+1 SIMPLE t3 ALL period NULL NULL NULL 41810 Using where; Using join buffer (flat, BNL join)
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=0;
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
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
@@ -615,6 +640,10 @@ explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period l
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index period period 4 NULL 1
1 SIMPLE t3 ref period period 4 test.t1.period 4181
+set @@join_cache_level=@save_join_cache_level;
+#
+# Search with a constant table.
+#
select period from t1;
period
9410
@@ -1378,18 +1407,28 @@ 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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999;
+#
+# Test left join optimization
+#
+set @save_join_cache_level=@@join_cache_level;
+set @@join_cache_level=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
+1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
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 t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
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 t2 ALL NULL NULL NULL NULL 1199 Using where
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
+set @@join_cache_level=@save_join_cache_level;
+explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
+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 t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (flat, BNL join)
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
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
@@ -1426,6 +1465,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
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
+#
+# Joins with forms.
+#
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr companynr
37 36
@@ -2364,16 +2406,16 @@ insert into t1 values (1,2), (2,2), (3,2), (4,2);
insert into t2 values (1,3), (2,3), (3,4), (4,4);
explain select * from t1 left join t2 on a=c where d in (4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2
select * from t1 left join t2 on a=c where d in (4);
a b c d
3 2 3 4
4 2 4 4
explain select * from t1 left join t2 on a=c where d = 4;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref c,d d 5 const 2
-1 SIMPLE t1 ALL a NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c,d d 5 const 2 Using where
+1 SIMPLE t1 ref a a 5 test.t2.c 2
select * from t1 left join t2 on a=c where d = 4;
a b c d
3 2 3 4
@@ -3479,7 +3521,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using index condition; Using where
+1 SIMPLE t1 range|filter PRIMARY,b b|PRIMARY 5|4 NULL 3 (90%) Using index condition; Using where; Using rowid filter
1 SIMPLE t2 ref c c 5 test.t1.a 2
DROP TABLE t1, t2;
create table t1 (
@@ -3540,7 +3582,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
+1 SIMPLE t3 ref idx1 idx1 5 const 4
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3640,7 +3682,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si si 5 NULL 2 Using index condition; Using where
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3648,7 +3690,7 @@ t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 2 Using index condition; Using where
-1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
DROP TABLE t1,t2,t3;
CREATE TABLE t1 ( f1 int primary key, f2 int, f3 int, f4 int, f5 int, f6 int, checked_out int);
CREATE TABLE t2 ( f11 int PRIMARY KEY );
@@ -3725,11 +3767,11 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (6%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|5 const 2 (27%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3739,7 +3781,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
+1 SIMPLE t1 ref|filter idx1,idx2 idx2|idx1 4|10 const 2 (7%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3773,7 +3815,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
+1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4039,7 +4081,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
+1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select_safe.result b/mysql-test/main/select_safe.result
index 18fc31b8bdc..a16d5439f48 100644
--- a/mysql-test/main/select_safe.result
+++ b/mysql-test/main/select_safe.result
@@ -75,8 +75,8 @@ id select_type table type possible_keys key key_len ref rows Extra
set MAX_SEEKS_FOR_KEY=1;
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL b NULL NULL NULL 11 Using where
-1 SIMPLE t2 ref b b 21 test.t1.b 5
+1 SIMPLE t1 ALL b NULL NULL NULL 11
+1 SIMPLE t2 ALL b NULL NULL NULL 11 Using where; Using join buffer (flat, BNL join)
SET MAX_SEEKS_FOR_KEY=DEFAULT;
drop table t1;
create table t1 (a int);
diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result
index 9ab15a08839..4514a35e7e7 100644
--- a/mysql-test/main/selectivity.result
+++ b/mysql-test/main/selectivity.result
@@ -74,16 +74,16 @@ s_acctbal desc, n_name, s_name, p_partkey;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using temporary; Using filesort
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 0.63 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where
+1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
-2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
-2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00
+2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
+2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and (`dbt3_s001`.`part`.`p_size` = 9 or `dbt3_s001`.`part`.`p_size` = 19999) and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
+Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and (`dbt3_s001`.`part`.`p_size` = 9 or `dbt3_s001`.`part`.`p_size` = 19999) and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`region`.`r_regionkey` = `dbt3_s001`.`nation`.`n_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
set optimizer_use_condition_selectivity=4;
explain extended
select
@@ -118,13 +118,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 2.08 Using where; Using join buffer (flat, BNL join)
1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where
-2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
-2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00
+2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
+2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
+Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`region`.`r_regionkey` = `dbt3_s001`.`nation`.`n_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
=== Q15 ===
create view revenue0 (supplier_no, total_revenue) as
select l_suppkey, sum(l_extendedprice * (1 - l_discount))
@@ -490,7 +490,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where
2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where
-4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where
+4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
@@ -542,7 +542,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where
-1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 11.99 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -597,7 +597,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.03 Using where
-1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 7.11 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -652,7 +652,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where
-1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 6.40 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -707,7 +707,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where
-1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 6.40 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -1641,27 +1641,51 @@ drop function f1;
#
create table t1 (a int, b int, key (b), key (a));
insert into t1
-select (rand(1)*1000)/10, (rand(1001)*1000)/20 from seq_1_to_1000;
-analyze table t1 persistent for all;
+select (rand(1)*1000)/30, (rand(1001)*1000)/40 from seq_1_to_1000;
+analyze table t1 ;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
+select count(*) from t1 where b=2;
+count(*)
+42
+select count(*) from t1 where a in (17,51,5);
+count(*)
+62
# Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.90 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 6.20 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`a` in (17,51,5)
explain extended select * from t1 use index () where b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.40 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 4.20 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`b` = 2
# Now, the equality is used for ref access, while the range condition
# gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (3%) 2.90 Using where; Using rowid filter
+1 SIMPLE t1 ref|filter b,a b|a 5|5 const 42 (6%) 6.30 Using where; Using rowid filter
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
+truncate table t1;
+insert into t1
+select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
+analyze table t1 ;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+select count(*) from t1 where b=2;
+count(*)
+59
+select count(*) from t1 where a in (17,51,5);
+count(*)
+29
+explain extended select * from t1 where a in (17,51,5) and b=2;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range|filter b,a a|b 5|5 NULL 29 (6%) 5.80 Using index condition; Using where; Using rowid filter
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
drop table t1;
@@ -1868,7 +1892,7 @@ WHERE A.a=t1.a AND t2.b < 20);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 Using where
2 DEPENDENT SUBQUERY A ref PRIMARY,a a 5 test.t1.a 1
-2 DEPENDENT SUBQUERY t2 ref a,b a 5 test.A.id 1 Using where
+2 DEPENDENT SUBQUERY t2 ref|filter a,b a|b 5|5 test.A.id 1 (10%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1 A, t1 B WHERE A.a = B.a and A.id = 65;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE A const PRIMARY,a PRIMARY 4 const 1
@@ -1880,7 +1904,7 @@ WHERE A.a=t1.a AND t2.b < 20);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 100 Using where
2 DEPENDENT SUBQUERY A ref PRIMARY,a a 5 test.t1.a 1
-2 DEPENDENT SUBQUERY t2 ref a,b a 5 test.A.id 1 Using where
+2 DEPENDENT SUBQUERY t2 ref|filter a,b a|b 5|5 test.A.id 1 (10%) Using where; Using rowid filter
set optimizer_switch= @save_optimizer_switch;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2;
diff --git a/mysql-test/main/selectivity.test b/mysql-test/main/selectivity.test
index f2992ac1073..a4fa09f0116 100644
--- a/mysql-test/main/selectivity.test
+++ b/mysql-test/main/selectivity.test
@@ -1113,8 +1113,10 @@ drop function f1;
--echo #
create table t1 (a int, b int, key (b), key (a));
insert into t1
-select (rand(1)*1000)/10, (rand(1001)*1000)/20 from seq_1_to_1000;
-analyze table t1 persistent for all;
+select (rand(1)*1000)/30, (rand(1001)*1000)/40 from seq_1_to_1000;
+analyze table t1 ;
+select count(*) from t1 where b=2;
+select count(*) from t1 where a in (17,51,5);
--echo # Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
@@ -1123,6 +1125,13 @@ explain extended select * from t1 use index () where b=2;
--echo # Now, the equality is used for ref access, while the range condition
--echo # gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
+truncate table t1;
+insert into t1
+select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
+analyze table t1 ;
+select count(*) from t1 where b=2;
+select count(*) from t1 where a in (17,51,5);
+explain extended select * from t1 where a in (17,51,5) and b=2;
drop table t1;
set use_stat_tables= @save_use_stat_tables;
@@ -1240,13 +1249,10 @@ set optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
drop table t1,t2,t3;
-
--echo #
--echo # MDEV-20519: Query plan regression with optimizer_use_condition_selectivity=4
--echo #
-
-
create table t1 (id int, a int, PRIMARY KEY(id), key(a));
insert into t1 select seq,seq from seq_1_to_100;
diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result
index 3797de29935..617aa350206 100644
--- a/mysql-test/main/selectivity_innodb.result
+++ b/mysql-test/main/selectivity_innodb.result
@@ -495,7 +495,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where
2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
-4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where
+4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
@@ -544,15 +544,15 @@ and n_name = 'UNITED STATES'
order by s_name
limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
-1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 4.17 Using where; FirstMatch(nation)
+1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 11.99 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
-Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
+Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
select sql_calc_found_rows
s_name, s_address
from supplier, nation
@@ -602,7 +602,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.03 Using where; FirstMatch(nation)
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 35.71 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -657,7 +657,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.81 Using where; FirstMatch(nation)
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 35.71 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -712,7 +712,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.81 Using where; FirstMatch(nation)
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 35.71 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -1648,27 +1648,51 @@ drop function f1;
#
create table t1 (a int, b int, key (b), key (a));
insert into t1
-select (rand(1)*1000)/10, (rand(1001)*1000)/20 from seq_1_to_1000;
-analyze table t1 persistent for all;
+select (rand(1)*1000)/30, (rand(1001)*1000)/40 from seq_1_to_1000;
+analyze table t1 ;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
+select count(*) from t1 where b=2;
+count(*)
+42
+select count(*) from t1 where a in (17,51,5);
+count(*)
+62
# Check what info the optimizer has about selectivities
explain extended select * from t1 use index () where a in (17,51,5);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.90 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 6.20 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`a` in (17,51,5)
explain extended select * from t1 use index () where b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 2.40 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1000 4.20 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () where `test`.`t1`.`b` = 2
# Now, the equality is used for ref access, while the range condition
# gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ref|filter b,a b|a 5|5 const 59 (3%) 2.90 Using where; Using rowid filter
+1 SIMPLE t1 ref|filter b,a b|a 5|5 const 42 (6%) 6.30 Using where; Using rowid filter
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
+truncate table t1;
+insert into t1
+select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
+analyze table t1 ;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+select count(*) from t1 where b=2;
+count(*)
+59
+select count(*) from t1 where a in (17,51,5);
+count(*)
+29
+explain extended select * from t1 where a in (17,51,5) and b=2;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range|filter b,a a|b 5|5 NULL 29 (6%) 5.90 Using index condition; Using where; Using rowid filter
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
drop table t1;
@@ -1776,7 +1800,7 @@ explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3
where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 10 NULL 11 100.00 Using index condition; Using where
-1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00 Using index
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00
Warnings:
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`c` and `test`.`t3`.`a` = `test`.`t1`.`d` and `test`.`t1`.`a` = 50 and `test`.`t1`.`b` <= 100
@@ -1797,8 +1821,8 @@ set optimizer_use_condition_selectivity=2;
explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3
where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range a a 10 NULL 11 11.00 Using index condition; Using where
-1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00 Using index
+1 SIMPLE t1 range a a 10 NULL 11 100.00 Using index condition; Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00
Warnings:
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`c` and `test`.`t3`.`a` = `test`.`t1`.`d` and `test`.`t1`.`a` = 50 and `test`.`t1`.`b` <= 100
@@ -1815,6 +1839,18 @@ b a a b
7 7 8 8
8 8 9 9
9 9 10 10
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3
+where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range a a 10 NULL 11 100.00 Using index condition; Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00
+1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00
+Warnings:
+Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`c` and `test`.`t3`.`a` = `test`.`t1`.`d` and `test`.`t1`.`a` = 50 and `test`.`t1`.`b` <= 100
set optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
drop table t1,t2,t3;
#
@@ -1863,7 +1899,7 @@ WHERE A.a=t1.a AND t2.b < 20);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 5 NULL 100 Using where; Using index
2 DEPENDENT SUBQUERY A ref PRIMARY,a a 5 test.t1.a 1 Using index
-2 DEPENDENT SUBQUERY t2 ref a,b a 5 test.A.id 1 Using where
+2 DEPENDENT SUBQUERY t2 ref|filter a,b a|b 5|5 test.A.id 1 (19%) Using where; Using rowid filter
EXPLAIN SELECT * FROM t1 A, t1 B WHERE A.a = B.a and A.id = 65;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE A const PRIMARY,a PRIMARY 4 const 1
@@ -1875,7 +1911,7 @@ WHERE A.a=t1.a AND t2.b < 20);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 5 NULL 100 Using where; Using index
2 DEPENDENT SUBQUERY A ref PRIMARY,a a 5 test.t1.a 1 Using index
-2 DEPENDENT SUBQUERY t2 ref a,b a 5 test.A.id 1 Using where
+2 DEPENDENT SUBQUERY t2 ref|filter a,b a|b 5|5 test.A.id 1 (19%) Using where; Using rowid filter
set optimizer_switch= @save_optimizer_switch;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2;
diff --git a/mysql-test/main/selectivity_no_engine.result b/mysql-test/main/selectivity_no_engine.result
index 552a16d8334..3811b12a1be 100644
--- a/mysql-test/main/selectivity_no_engine.result
+++ b/mysql-test/main/selectivity_no_engine.result
@@ -236,8 +236,8 @@ set optimizer_use_condition_selectivity=2;
explain
select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL f1 NULL NULL NULL 4 Using where
-1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref f1 f1 325 const,const 2 Using index condition; Using where
+1 SIMPLE t1 eq_ref PRIMARY PRIMARY 122 test.t2.t1_id 1
select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
id dt t1_id f1 f2
foo 2011-04-12 05:18:08 foo baz qux
diff --git a/mysql-test/main/show_explain.result b/mysql-test/main/show_explain.result
index aa3be6f1f58..1888052647b 100644
--- a/mysql-test/main/show_explain.result
+++ b/mysql-test/main/show_explain.result
@@ -40,7 +40,7 @@ select count(*) from t1 where a < 100000;
connection default;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index a a 5 NULL 1000 Using where; Using index
+1 SIMPLE t1 range a a 5 NULL 999 Using where; Using index
Warnings:
Note 1003 select count(*) from t1 where a < 100000
connection con1;
diff --git a/mysql-test/main/sp.result b/mysql-test/main/sp.result
index 04f6a071112..37c22e45b45 100644
--- a/mysql-test/main/sp.result
+++ b/mysql-test/main/sp.result
@@ -2173,8 +2173,8 @@ create procedure bug3734 (param1 varchar(100))
select * from t3 where match (title,body) against (param1)|
call bug3734('database')|
id title body
-1 MySQL Tutorial DBMS stands for DataBase ...
5 MySQL vs. YourSQL In the following database comparison ...
+1 MySQL Tutorial DBMS stands for DataBase ...
call bug3734('Security')|
id title body
6 MySQL Security When configured properly, MySQL ...
diff --git a/mysql-test/main/ssl.result b/mysql-test/main/ssl.result
index 794830e5529..2694d177056 100644
--- a/mysql-test/main/ssl.result
+++ b/mysql-test/main/ssl.result
@@ -9,6 +9,7 @@ SHOW STATUS LIKE 'Ssl_server_not_after';
Variable_name Value
Ssl_server_not_after Feb 27 03:03:03 2040 GMT
drop table if exists t1,t2,t3,t4;
+set @@default_storage_engine="aria";
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
@@ -609,6 +610,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
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
+#
+# Some test with ORDER BY and limit
+#
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
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
@@ -1298,7 +1302,7 @@ companynr tinyint(2) unsigned zerofill NOT NULL default '00',
companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr),
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;
companynr companyname
00 Unknown
@@ -1388,6 +1392,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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
@@ -1402,15 +1409,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
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
-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
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
-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
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
-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
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
@@ -1426,11 +1433,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
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
-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
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
-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
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
diff --git a/mysql-test/main/ssl_compress.result b/mysql-test/main/ssl_compress.result
index 69de425cdc1..beb21ce8b16 100644
--- a/mysql-test/main/ssl_compress.result
+++ b/mysql-test/main/ssl_compress.result
@@ -6,6 +6,7 @@ SHOW STATUS LIKE 'Compression';
Variable_name Value
Compression ON
drop table if exists t1,t2,t3,t4;
+set @@default_storage_engine="aria";
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' 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
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
+#
+# Some test with ORDER BY and limit
+#
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
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 '',
PRIMARY KEY (companynr),
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;
companynr companyname
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
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
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;
id select_type table type possible_keys key key_len ref rows Extra
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
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
-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
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
-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
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
-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
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
@@ -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
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
-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
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
-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
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
diff --git a/mysql-test/main/stat_tables.result b/mysql-test/main/stat_tables.result
index 35659bc0076..d9ee8cf14c4 100644
--- a/mysql-test/main/stat_tables.result
+++ b/mysql-test/main/stat_tables.result
@@ -214,10 +214,10 @@ order by o_year;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using temporary; Using filesort
1 SIMPLE part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_partkey 5 dbt3_s001.part.p_partkey 30 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 5 dbt3_s001.part.p_partkey 30 Using index condition
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
-1 SIMPLE orders eq_ref PRIMARY,i_o_orderdate,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
+1 SIMPLE orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (27%) Using where; Using rowid filter
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 Using where
select o_year,
@@ -251,12 +251,32 @@ and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 Using where; Using temporary; Using filesort
+1 SIMPLE part ALL PRIMARY NULL NULL NULL 200 Using where; Using temporary; Using filesort
+1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3
+1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
-1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70
-1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.part.p_partkey,dbt3_s001.partsupp.ps_suppkey 8
1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1
+EXPLAIN EXTENDED select nation, o_year, sum(amount) as sum_profit
+from (select n_name as nation,
+extract(year from o_orderdate) as o_year,
+l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+from part, supplier, lineitem, partsupp, orders, nation
+where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
+and ps_partkey = l_partkey and p_partkey = l_partkey
+and o_orderkey = l_orderkey and s_nationkey = n_nationkey
+and p_name like '%green%') as profit
+group by nation, o_year
+order by nation, o_year desc;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE part ALL PRIMARY NULL NULL NULL 200 100.00 Using where; Using temporary; Using filesort
+1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00
+1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 10.00 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.part.p_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00
+1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 100.00
+Warnings:
+Note 1003 select `dbt3_s001`.`nation`.`n_name` AS `nation`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) AS `o_year`,sum(`dbt3_s001`.`lineitem`.`l_extendedprice` * (1 - `dbt3_s001`.`lineitem`.`l_discount`) - `dbt3_s001`.`partsupp`.`ps_supplycost` * `dbt3_s001`.`lineitem`.`l_quantity`) AS `sum_profit` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`lineitem` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`orders` join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`orders`.`o_orderkey` = `dbt3_s001`.`lineitem`.`l_orderkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`part`.`p_name` like '%green%' group by `dbt3_s001`.`nation`.`n_name`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) desc order by `dbt3_s001`.`nation`.`n_name`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) desc
select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
@@ -337,7 +357,7 @@ and o_orderkey=l_orderkey and p_partkey=l_partkey;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE part range PRIMARY,i_p_retailprice i_p_retailprice 9 NULL 1 Using index condition
1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
@@ -591,8 +611,8 @@ set @@use_stat_tables= PREFERABLY;
explain
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
-1 SIMPLE global_priv ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+1 SIMPLE global_priv ALL NULL NULL NULL NULL 5
+1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL Using join buffer (flat, BNL join)
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
#
@@ -852,7 +872,6 @@ set histogram_size=0;
#
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
-insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
@@ -866,7 +885,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
# analyze table t1 will collect statistics if we use PERSISTENT
@@ -878,12 +897,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
+test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where
#
# with use_stat_tables= PREFERABLY
# analyze table t1 will collect statistics
@@ -895,13 +914,13 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
-test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL
+test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
+test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a=1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 2.78 10.00 Using where
drop table t1;
set @@global.histogram_size=@save_histogram_size;
# End of 10.4 tests
diff --git a/mysql-test/main/stat_tables.test b/mysql-test/main/stat_tables.test
index fccae8d88c4..8b9f8361d55 100644
--- a/mysql-test/main/stat_tables.test
+++ b/mysql-test/main/stat_tables.test
@@ -141,6 +141,7 @@ group by nation, o_year
order by nation, o_year desc;
eval EXPLAIN $Q9;
+eval EXPLAIN EXTENDED $Q9;
eval $Q9;
@@ -603,7 +604,6 @@ set histogram_size=0;
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
-insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
--echo #
--echo # with use_stat_tables= PREFERABLY_FOR_QUERIES
diff --git a/mysql-test/main/stat_tables_innodb.result b/mysql-test/main/stat_tables_innodb.result
index f874f6a0ff6..c90e99a9bbf 100644
--- a/mysql-test/main/stat_tables_innodb.result
+++ b/mysql-test/main/stat_tables_innodb.result
@@ -77,12 +77,12 @@ and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using temporary; Using filesort
-1 SIMPLE nation ref PRIMARY,i_n_regionkey i_n_regionkey 5 dbt3_s001.region.r_regionkey 5
-1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 Using index
-1 SIMPLE customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6 Using index
+1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 Using where; Using index; Using temporary; Using filesort
+1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 Using where
+1 SIMPLE region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 Using where
+1 SIMPLE customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.supplier.s_nationkey 6 Using index
1 SIMPLE orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; Using rowid filter
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 9 dbt3_s001.supplier.s_suppkey,dbt3_s001.orders.o_orderkey 1
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
@@ -208,12 +208,12 @@ and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using temporary; Using filesort
-1 SIMPLE nation ref PRIMARY,i_n_regionkey i_n_regionkey 5 dbt3_s001.region.r_regionkey 5
-1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 Using index
-1 SIMPLE customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6 Using index
+1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 Using where; Using index; Using temporary; Using filesort
+1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 Using where
+1 SIMPLE region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 Using where
+1 SIMPLE customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.supplier.s_nationkey 6 Using index
1 SIMPLE orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; Using rowid filter
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 9 dbt3_s001.supplier.s_suppkey,dbt3_s001.orders.o_orderkey 1
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
@@ -246,7 +246,7 @@ order by o_year;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using temporary; Using filesort
1 SIMPLE part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
-1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_partkey 5 dbt3_s001.part.p_partkey 30 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 5 dbt3_s001.part.p_partkey 30 Using index condition
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
1 SIMPLE orders eq_ref PRIMARY,i_o_orderdate,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
@@ -289,6 +289,26 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8
1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1
+EXPLAIN EXTENDED select nation, o_year, sum(amount) as sum_profit
+from (select n_name as nation,
+extract(year from o_orderdate) as o_year,
+l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+from part, supplier, lineitem, partsupp, orders, nation
+where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
+and ps_partkey = l_partkey and p_partkey = l_partkey
+and o_orderkey = l_orderkey and s_nationkey = n_nationkey
+and p_name like '%green%') as profit
+group by nation, o_year
+order by nation, o_year desc;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 100.00 Using where; Using index; Using temporary; Using filesort
+1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00
+1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00
+1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 100.00 Using where
+1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8 100.00
+1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 100.00
+Warnings:
+Note 1003 select `dbt3_s001`.`nation`.`n_name` AS `nation`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) AS `o_year`,sum(`dbt3_s001`.`lineitem`.`l_extendedprice` * (1 - `dbt3_s001`.`lineitem`.`l_discount`) - `dbt3_s001`.`partsupp`.`ps_supplycost` * `dbt3_s001`.`lineitem`.`l_quantity`) AS `sum_profit` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`lineitem` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`orders` join `dbt3_s001`.`nation` where `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`orders`.`o_orderkey` = `dbt3_s001`.`lineitem`.`l_orderkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`part`.`p_name` like '%green%' group by `dbt3_s001`.`nation`.`n_name`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) desc order by `dbt3_s001`.`nation`.`n_name`,extract(year from `dbt3_s001`.`orders`.`o_orderDATE`) desc
select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
@@ -623,8 +643,8 @@ set @@use_stat_tables= PREFERABLY;
explain
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
-1 SIMPLE global_priv ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+1 SIMPLE global_priv ALL NULL NULL NULL NULL 5
+1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL Using join buffer (flat, BNL join)
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
#
@@ -884,7 +904,6 @@ set histogram_size=0;
#
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
-insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
@@ -898,7 +917,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
# analyze table t1 will collect statistics if we use PERSISTENT
@@ -910,12 +929,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
+test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where
#
# with use_stat_tables= PREFERABLY
# analyze table t1 will collect statistics
@@ -927,13 +946,13 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
-test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL
+test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
+test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a=1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 2.78 10.00 Using where
drop table t1;
set @@global.histogram_size=@save_histogram_size;
# End of 10.4 tests
diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result
index 375ed45afbc..748287152b1 100644
--- a/mysql-test/main/statistics_json.result
+++ b/mysql-test/main/statistics_json.result
@@ -4643,7 +4643,7 @@ Warnings:
Note 1003 select `test`.`t1_json`.`a` AS `a` from `test`.`t1_json` where `test`.`t1_json`.`a` < 'b-1a'
analyze select * from t1_json where a > 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 10.00 10.00 0.00 Using where
+1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 10.00 0.00 0.00 Using where
drop table ten;
UPDATE mysql.column_stats
SET histogram='["not-what-you-expect"]' WHERE table_name='t1_json';
diff --git a/mysql-test/main/status.result b/mysql-test/main/status.result
index ae64f370e45..0669bdf3b34 100644
--- a/mysql-test/main/status.result
+++ b/mysql-test/main/status.result
@@ -71,10 +71,10 @@ a
6
show status like 'last_query_cost';
Variable_name Value
-Last_query_cost 0.017820
+Last_query_cost 0.017856
show status like 'last_query_cost';
Variable_name Value
-Last_query_cost 0.017820
+Last_query_cost 0.017856
select 1;
1
1
@@ -134,20 +134,20 @@ a
1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
EXPLAIN SELECT a FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a;
a
1
2
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
EXPLAIN SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
@@ -155,25 +155,25 @@ id select_type table type possible_keys key key_len ref rows Extra
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using filesort
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
SELECT a IN (SELECT a FROM t1) FROM t1 LIMIT 1;
a IN (SELECT a FROM t1)
1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
SELECT (SELECT a FROM t1 LIMIT 1) x FROM t1 LIMIT 1;
x
1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.010313
+Last_query_cost 0.010348
SELECT * FROM t1 a, t1 b LIMIT 1;
a a
1 1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 0.021119
+Last_query_cost 0.021190
DROP TABLE t1;
connect con1,localhost,root,,;
show status like 'com_show_status';
diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result
index 478404fcefe..b3d69a547d1 100644
--- a/mysql-test/main/subselect.result
+++ b/mysql-test/main/subselect.result
@@ -345,7 +345,7 @@ patient_uq clinic_uq
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t7 index PRIMARY PRIMARY 4 NULL 2 100.00 Using index
-1 PRIMARY t6 ALL i1 NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t6 ref i1 i1 5 test.t7.uq 2 100.00
Warnings:
Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t7` join `test`.`t6` where `test`.`t6`.`clinic_uq` = `test`.`t7`.`uq`
@@ -1429,6 +1429,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1475,42 +1478,48 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
+explain extended select * from t2 where t2.a in (select a from t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using index; FirstMatch(t2)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select a from t1);
a
2
3
4
-explain extended select * from t2 where t2.a in (select a from t1);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 0.29 Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
-explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
-insert into t1 values (3,31);
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1520,12 +1529,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
-Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1587,6 +1590,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1614,21 +1620,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2420,22 +2426,23 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 25 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
+Note 1003 select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -3103,6 +3110,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3118,7 +3129,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3130,7 +3141,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4230,8 +4241,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4332,6 +4343,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -4393,8 +4407,8 @@ CREATE INDEX I1 ON t1 (a);
CREATE INDEX I2 ON t1 (b);
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
a b
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
@@ -4403,15 +4417,15 @@ CREATE INDEX I1 ON t2 (a);
CREATE INDEX I2 ON t2 (b);
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t2 index I1 I1 4 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t2 ref I2 I2 13 test.t2.a 2 Using index condition
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
a b
EXPLAIN
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
a b
DROP TABLE t1,t2;
@@ -4456,11 +4470,10 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 select 2 AS `2` from `test`.`t1` semi join (`test`.`t2`) where 1
+Note 1003 select 2 AS `2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`a`
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
@@ -5707,6 +5720,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5717,7 +5731,7 @@ WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 502
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5727,7 +5741,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
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 t2 ref idx idx 5 test.t1.a 2 Using index; FirstMatch(t1)
+1 PRIMARY t2 ref idx idx 5 test.t1.a 11 Using index; FirstMatch(t1)
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
@@ -5744,9 +5758,9 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3
-1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index
-1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(it)
+1 PRIMARY it index PRIMARY PRIMARY 4 NULL 3 Using index
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.it.pk 1
+1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
pk i
11 0
diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test
index 461d518d99f..48ad7402755 100644
--- a/mysql-test/main/subselect.test
+++ b/mysql-test/main/subselect.test
@@ -907,9 +907,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
-#
-# IN subselect optimization test
-#
+--echo #
+--echo # IN subselect optimization test
+--echo #
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -931,20 +931,20 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
-select * from t2 where t2.a in (select a from t1);
explain extended select * from t2 where t2.a in (select a from t1);
-select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+select * from t2 where t2.a in (select a from t1);
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
drop table t0, t1, t2, t3;
#
@@ -1018,9 +1018,9 @@ explain extended (select * from t1);
(select * from t1);
drop table t1;
-#
-# IN optimisation test results
-#
+--echo #
+--echo # IN optimisation test results
+--echo #
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1452,15 +1452,16 @@ SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2');
DROP TABLE t1;
-#
-# SELECT(EXISTS * ...)optimisation
-#
+--echo #
+--echo # SELECT(EXISTS * ...)optimisation
+--echo #
#--view-protocol is disabled because view gives another query plan
--disable_view_protocol
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
drop table t1;
--enable_view_protocol
@@ -2061,10 +2062,10 @@ select * from t1 r1
drop table t1;
-#
-# Bug#21180 Subselect with index for both WHERE and ORDER BY
-# produces empty result
-#
+--echo #
+--echo # Bug#21180 Subselect with index for both WHERE and ORDER BY
+--echo # produces empty result
+--echo #
create table t1(a int, primary key (a));
insert into t1 values (10);
@@ -3100,6 +3101,7 @@ INSERT INTO t1 VALUES
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id));
INSERT INTO t2 VALUES (7), (5), (1), (3);
+--sorted_result
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
SELECT id, st FROM t1
@@ -3274,9 +3276,9 @@ DROP TABLE t1, t2;
#--enable_query_log
#drop table t1;
-#
-# Bug#28076 inconsistent binary/varbinary comparison
-#
+--echo #
+--echo # Bug#28076 inconsistent binary/varbinary comparison
+--echo #
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
@@ -4856,6 +4858,7 @@ INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
diff --git a/mysql-test/main/subselect2.result b/mysql-test/main/subselect2.result
index dea2a963caf..1af4328aecc 100644
--- a/mysql-test/main/subselect2.result
+++ b/mysql-test/main/subselect2.result
@@ -277,7 +277,7 @@ KEY `date` (`date`)
INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
-explain
+set statement optimizer_scan_setup_cost=0 for explain
SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
@@ -286,9 +286,9 @@ WHERE date < '2012-12-12 12:12:12'
ORDER BY mirror_date ASC
) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
-2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort
-SELECT * FROM (
+1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3
+3 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort
+set statement optimizer_scan_setup_cost=0 FOR SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
WHERE date < '2012-12-12 12:12:12'
@@ -310,7 +310,7 @@ ORDER BY mirror_date ASC
) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
-2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort
+2 DERIVED t1 range date date 6 NULL 3 Using index condition; Using where; Using filesort
SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
diff --git a/mysql-test/main/subselect2.test b/mysql-test/main/subselect2.test
index b341e516941..0780a5b9319 100644
--- a/mysql-test/main/subselect2.test
+++ b/mysql-test/main/subselect2.test
@@ -303,7 +303,7 @@ INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00');
INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00');
INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00');
-explain
+set statement optimizer_scan_setup_cost=0 for explain
SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
@@ -312,7 +312,7 @@ SELECT * FROM (
ORDER BY mirror_date ASC
) AS calculated_result;
-SELECT * FROM (
+set statement optimizer_scan_setup_cost=0 FOR SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
WHERE date < '2012-12-12 12:12:12'
diff --git a/mysql-test/main/subselect3.result b/mysql-test/main/subselect3.result
index 36063f3e594..c41b3e3c48f 100644
--- a/mysql-test/main/subselect3.result
+++ b/mysql-test/main/subselect3.result
@@ -1157,9 +1157,9 @@ set @@optimizer_switch='firstmatch=off,materialization=off';
set @@max_heap_table_size= 16384;
explain select count(*) from t0 A, t0 B, t0 C, t0 D where D.a in (select a from t1 E where a+1 < 10000 + A.a + B.a +C.a+D.a);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY A ALL NULL NULL NULL NULL 10
+1 PRIMARY E ALL NULL NULL NULL NULL 5 Start temporary
+1 PRIMARY A ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
1 PRIMARY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
-1 PRIMARY E ALL NULL NULL NULL NULL 5 Start temporary; Using join buffer (flat, BNL join)
1 PRIMARY C ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
1 PRIMARY D ALL NULL NULL NULL NULL 10 Using where; End temporary; Using join buffer (flat, BNL join)
flush status;
@@ -1341,9 +1341,9 @@ count(*)
explain select * from t1 where (a,b,c) in (select X.a, Y.a, Z.a from t2 X, t2 Y, t2 Z where X.b=33);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
-1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where
-1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where
-1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; FirstMatch(t1)
+1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; End temporary; Using join buffer (flat, BNL join)
drop table t0,t1,t2;
set @@optimizer_switch=@save_optimizer_switch;
@@ -1418,7 +1418,7 @@ WHERE cona.postalStripped='T2H3B2'
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY cona ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary
1 PRIMARY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00 Using where
-1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.c.idObj 1 100.00 Using index; End temporary
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.c.idObj 1 50.00 Using index; End temporary
Warnings:
Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where `test`.`cona`.`postalStripped` = 'T2H3B2' and `test`.`a`.`idIndividual` = `test`.`c`.`idObj` and `test`.`c`.`idContact` = `test`.`cona`.`idContact`
SELECT a.idIndividual FROM t1 a
diff --git a/mysql-test/main/subselect3_jcl6.result b/mysql-test/main/subselect3_jcl6.result
index 41f280b5bd0..13f61b7d101 100644
--- a/mysql-test/main/subselect3_jcl6.result
+++ b/mysql-test/main/subselect3_jcl6.result
@@ -622,8 +622,8 @@ aa 1 1
bb NULL NULL
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
oref a
-cc 5
aa 1
+cc 5
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
oref a
ee NULL
@@ -1160,9 +1160,9 @@ set @@optimizer_switch='firstmatch=off,materialization=off';
set @@max_heap_table_size= 16384;
explain select count(*) from t0 A, t0 B, t0 C, t0 D where D.a in (select a from t1 E where a+1 < 10000 + A.a + B.a +C.a+D.a);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY A ALL NULL NULL NULL NULL 10
-1 PRIMARY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
-1 PRIMARY E ALL NULL NULL NULL NULL 5 Using where; Start temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY E ALL NULL NULL NULL NULL 5 Using where; Start temporary
+1 PRIMARY A ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
+1 PRIMARY B ALL NULL NULL NULL NULL 10 Using join buffer (incremental, BNL join)
1 PRIMARY C ALL NULL NULL NULL NULL 10 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY D hash_ALL NULL #hash#$hj 5 test.E.a 10 Using where; End temporary; Using join buffer (incremental, BNLH join)
flush status;
@@ -1421,7 +1421,7 @@ WHERE cona.postalStripped='T2H3B2'
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY cona ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary
1 PRIMARY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.c.idObj 1 100.00 Using index; End temporary
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.c.idObj 1 50.00 Using index; End temporary
Warnings:
Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where `test`.`cona`.`postalStripped` = 'T2H3B2' and `test`.`a`.`idIndividual` = `test`.`c`.`idObj` and `test`.`c`.`idContact` = `test`.`cona`.`idContact`
SELECT a.idIndividual FROM t1 a
diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result
index 48fe29344a5..c96379ee856 100644
--- a/mysql-test/main/subselect4.result
+++ b/mysql-test/main/subselect4.result
@@ -1367,8 +1367,8 @@ GROUP BY SQ1_t1.f4));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
-3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary
-3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+3 SUBQUERY SQ1_t3 range f4 f4 5 NULL 2 Using where; Using index; Using temporary
+3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE
(SELECT f2 FROM t2
WHERE f4 <= ALL
@@ -1388,8 +1388,8 @@ INSERT INTO t2 VALUES (1), (2);
EXPLAIN
SELECT i FROM t1 WHERE (1) NOT IN (SELECT i FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
-2 SUBQUERY t2 index k k 5 NULL 2 Using where; Using index
+1 PRIMARY t1 system NULL NULL NULL NULL 1
+2 SUBQUERY t2 index_subquery k k 5 const 2 Using index
DROP TABLE t2;
DROP TABLE t1;
#
@@ -1785,7 +1785,7 @@ SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY t3 system NULL NULL NULL NULL 1
-2 SUBQUERY t2 index f10 f10 10 NULL 2 Using where; Using index
+2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index
SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10);
f4
drop table t1,t2,t3;
@@ -2758,15 +2758,15 @@ from t2 join t1 on
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
1 PRIMARY t1 index NULL v1 9 NULL 5 Using index
-2 SUBQUERY t1 ref_or_null v1 v1 4 const 3 Using where; Using index
-2 SUBQUERY t3 ALL NULL NULL NULL NULL 4 Using where
-2 SUBQUERY t4 ALL NULL NULL NULL NULL 50 Using where
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 Using where
+2 MATERIALIZED t1 ref v1 v1 4 test.t3.v2 1 Using index
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 50
select 1
from t2 join t1 on
('i','w') not in (select t1.v1,t4.v2 from t4,t1,t3 where t3.v2 = t1.v1) LIMIT ROWS EXAMINED 10;
1
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 11 rows, which exceeds LIMIT ROWS EXAMINED (10). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 14 rows, which exceeds LIMIT ROWS EXAMINED (10). The query result may be incomplete
SET join_cache_level= @save_join_cache_level;
DROP TABLE t1,t2,t3,t4;
#
diff --git a/mysql-test/main/subselect_exists2in.result b/mysql-test/main/subselect_exists2in.result
index 7b3966c3f93..45655afe662 100644
--- a/mysql-test/main/subselect_exists2in.result
+++ b/mysql-test/main/subselect_exists2in.result
@@ -51,8 +51,8 @@ c
explain extended
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index aa aa 4 NULL 2 100.00 Using index
-1 PRIMARY t3 ALL bb NULL NULL NULL 2 75.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+1 PRIMARY t1 index aa aa 4 NULL 2 100.00 Using where; Using index
+1 PRIMARY t3 ref bb bb 4 test.t1.a 2 50.00 FirstMatch(t1)
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3`) where `test`.`t3`.`b` = `test`.`t1`.`a`
@@ -65,10 +65,10 @@ explain extended
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where
+2 DEPENDENT SUBQUERY t3 index_subquery bb bb 4 func 2 100.00
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t3`.`b` from `test`.`t3` where <cache>(`test`.`t1`.`a`) = `test`.`t3`.`b`))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t3 on bb)))
-- EXIST2IN then MATERIALIZATION
set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
@@ -91,7 +91,7 @@ explain extended
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where
+2 DEPENDENT SUBQUERY t3 ref bb bb 4 test.t1.a 2 100.00
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(/* select#2 */ select `test`.`t3`.`a` from `test`.`t3` where `test`.`t3`.`b` = `test`.`t1`.`a` limit 1)
@@ -304,6 +304,7 @@ CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (7),(0),(100);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (0),(8),(1000),(2000),(3000),(4000),(5000);
+insert into t2 select seq from seq_6000_to_6100;
SELECT * FROM t1 WHERE
EXISTS ( SELECT * FROM t2 WHERE b = a )
OR a > 0;
@@ -317,7 +318,7 @@ EXISTS ( SELECT * FROM t2 WHERE b = a )
OR a > 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 108 100.00
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`b` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`b`)))) or `test`.`t1`.`a` > 0
@@ -390,7 +391,7 @@ explain extended
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 index bb bb 8 NULL 2 100.00 Using where; Using index; LooseScan
-1 PRIMARY t1 ref aa aa 8 test.t3.b,test.t3.b1 2 100.00 Using index
+1 PRIMARY t1 ref aa aa 8 test.t3.b,test.t3.b1 2 50.00 Using index
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1
@@ -626,7 +627,7 @@ SELECT * FROM t1 AS alias
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 50.00 Using where; Start temporary; End temporary
Warnings:
Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1
@@ -719,12 +720,13 @@ set optimizer_switch='exists_to_in=on';
create table t1 (col1 int, col2 int, col3 int);
insert into t1 values (1,2,3),(2,3,4),(4,5,6),(7,8,9);
create table t2 as select * from t1;
+insert into t2 select seq,seq,seq from seq_1000_to_1200;
explain extended
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 205 100.00
Warnings:
Note 1276 Field or reference 'test.t1.col1' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.t1.col2' of SELECT #2 was resolved in SELECT #1
@@ -907,7 +909,7 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 50.00 Using where; FirstMatch
3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1
@@ -926,7 +928,7 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 50.00 Using where; FirstMatch
3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1
diff --git a/mysql-test/main/subselect_exists2in.test b/mysql-test/main/subselect_exists2in.test
index cf06e7cbd2c..625c007e006 100644
--- a/mysql-test/main/subselect_exists2in.test
+++ b/mysql-test/main/subselect_exists2in.test
@@ -1,4 +1,5 @@
--source include/default_optimizer_switch.inc
+--source include/have_sequence.inc
--disable_warnings
drop table if exists t1,t2,t3;
@@ -245,6 +246,7 @@ CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (7),(0),(100);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (0),(8),(1000),(2000),(3000),(4000),(5000);
+insert into t2 select seq from seq_6000_to_6100;
SELECT * FROM t1 WHERE
EXISTS ( SELECT * FROM t2 WHERE b = a )
@@ -573,6 +575,8 @@ set optimizer_switch='exists_to_in=on';
create table t1 (col1 int, col2 int, col3 int);
insert into t1 values (1,2,3),(2,3,4),(4,5,6),(7,8,9);
create table t2 as select * from t1;
+insert into t2 select seq,seq,seq from seq_1000_to_1200;
+
explain extended
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
diff --git a/mysql-test/main/subselect_exists2in_costmat.result b/mysql-test/main/subselect_exists2in_costmat.result
index 5630f8f275a..1c9574aafd3 100644
--- a/mysql-test/main/subselect_exists2in_costmat.result
+++ b/mysql-test/main/subselect_exists2in_costmat.result
@@ -64,8 +64,8 @@ Code = Country) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country range Name,SurfaceArea SurfaceArea 4 NULL 71 Using index condition; Using where; Rowid-ordered scan
-2 DEPENDENT SUBQUERY City index_subquery Population,Country Country 3 func 17 Using where
+1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where
+2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
SELECT Name FROM Country
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
Code = Country) OR
diff --git a/mysql-test/main/subselect_innodb.result b/mysql-test/main/subselect_innodb.result
index c95cf3abb37..b74ad66366f 100644
--- a/mysql-test/main/subselect_innodb.result
+++ b/mysql-test/main/subselect_innodb.result
@@ -462,7 +462,7 @@ EXPLAIN
SELECT * FROM t1 WHERE EXISTS ( SELECT b FROM t2, t3 GROUP BY b HAVING b != 3 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
-2 SUBQUERY t2 index NULL PRIMARY 4 NULL 1 Using index; Using temporary
+2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 Using temporary
2 SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE EXISTS ( SELECT b FROM t2, t3 GROUP BY b HAVING b != 3 );
a
@@ -612,7 +612,7 @@ INNER JOIN
ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
ON ( f1 >= f2 );
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 50.00 Using where; FirstMatch
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result
index eef237ef8de..d939078c897 100644
--- a/mysql-test/main/subselect_mat.result
+++ b/mysql-test/main/subselect_mat.result
@@ -105,7 +105,7 @@ explain extended
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
-2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i range it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1`))))
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
@@ -127,7 +127,7 @@ explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
-2 MATERIALIZED t2i index it2i1,it2i3 it2i3 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i range it2i1,it2i3 it2i3 # NULL 5 100.00 Using where;
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`))))
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
@@ -340,7 +340,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL # # # 3 100.00 #
3 MATERIALIZED t3i index NULL # # # 4 100.00 #
4 MATERIALIZED t2i index it2i2 # # # 5 100.00 #
-2 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 #
+2 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#3 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery4>`.`b1` and `test`.`t3i`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery3>`.`c1` and `test`.`t1i`.`a2` = `<subquery3>`.`c2`))))
select * from t1i
@@ -423,7 +423,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
7 UNION t1i index NULL # # # 3 100.00 #
9 MATERIALIZED t3i index NULL # # # 4 100.00 #
10 MATERIALIZED t2i index it2i2 # # # 5 100.00 #
-8 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 #
+8 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
Warnings:
Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery6>`.`b1` and `test`.`t3`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5>`.`c2`))))) union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#8 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery8>`.`b1` and `test`.`t1i`.`a2` = `<subquery8>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#9 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#10 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery10>`.`b1` and `test`.`t3i`.`c2` = `<subquery10>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery9>`.`c1` and `test`.`t1i`.`a2` = `<subquery9>`.`c2`)))))
@@ -1142,7 +1142,7 @@ a
explain extended
select a from t1 group by a having a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL it1a 4 NULL 7 100.00 Using index for group-by
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`))))
@@ -1154,7 +1154,7 @@ create index iab on t1(a, b);
explain extended
select a from t1 group by a having a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL it1a 4 NULL 7 100.00 Using index for group-by
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`))))
@@ -1166,7 +1166,7 @@ explain extended
select a from t1 group by a
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL iab 4 NULL 7 100.00 Using index for group-by
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
@@ -1516,6 +1516,9 @@ COUNT(*)
2
set @@optimizer_switch= @local_optimizer_switch;
DROP TABLE t1, t2;
+#
+# BUG#46548 IN-subqueries return 0 rows with materialization=on
+#
CREATE TABLE t1 (
pk int,
a varchar(1),
@@ -1525,15 +1528,19 @@ d varchar(4),
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
+insert into t1 select seq,'x','xxxx','xxxx','xxxx' from seq_10_to_40;
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
+insert into t2 select -seq,'a','aaaa','aaaa','aaaa' from seq_1_to_20;
+insert into t2 select seq,'b','bbbb','bbbb','bbbb' from seq_100_to_200;
set @local_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 33
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL PRIMARY NULL NULL NULL 123 Using where
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
pk
2
@@ -1887,20 +1894,21 @@ WHERE alias4.c = alias3.b
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
-3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2
-3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2 Using where
+3 MATERIALIZED alias4 ref c c 11 test.alias3.b 2 Using where; Using index
DROP TABLE t1,t2;
#
# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result
#
create table t1 (a int, b int);
insert into t1 values (7,5), (3,3), (5,4), (9,3);
+insert into t1 select seq,seq from seq_100_to_200;
create table t2 (a int, b int, index i_a(a));
insert into t2 values
(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1);
explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
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 105 Using where
2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where
select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
a b
@@ -2192,8 +2200,8 @@ mysqltest1
EXPLAIN EXTENDED
SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY schemata ALL NULL NULL NULL NULL NULL NULL Start temporary; Using temporary; Using filesort
-1 PRIMARY t1 eq_ref db db 764 information_schema.schemata.SCHEMA_NAME 1 100.00 Using where; Using index; End temporary
+1 PRIMARY t1 index db db 764 NULL 4 100.00 Using index; Using temporary; Using filesort
+1 PRIMARY schemata ALL NULL NULL NULL NULL NULL NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`db` AS `db` from `test`.`t1` semi join (`information_schema`.`schemata`) where `test`.`t1`.`db` = `information_schema`.`schemata`.`SCHEMA_NAME` order by `test`.`t1`.`db` desc
drop table t1;
@@ -2225,8 +2233,10 @@ drop table t1;
CREATE TABLE t1 (
pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
+create table t2 like t1;
+insert into t2 select * from t1;
SELECT sq1.f2 FROM t1 AS sq1
-WHERE EXISTS ( SELECT * FROM t1 AS sq2
+WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
@@ -2243,12 +2253,12 @@ id select_type table type possible_keys key key_len ref rows Extra
# this checks the result set above
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
-WHERE EXISTS ( SELECT * FROM t1 AS sq2
+WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
set optimizer_switch= @local_optimizer_switch;
-DROP TABLE t1;
+DROP TABLE t1,t2;
#
# MDEV-12145: IN subquery used in WHERE of EXISTS subquery
#
@@ -2271,8 +2281,8 @@ WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
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 Using where
-2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch
-2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 12.50 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 range i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
@@ -2309,7 +2319,7 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; FirstMatch
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
@@ -2393,11 +2403,10 @@ WHERE t2.ugroup = t3_i.sys_id AND
t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND
t2.user = '86826bf03710200044e0bfc8bcbe5d79');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
-1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where
+1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary
+1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
+1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index
-2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where
-2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
set statement optimizer_prune_level=1 for explain SELECT t1.assignment_group
FROM t1, t3
WHERE t1.assignment_group = t3.sys_id AND
@@ -2408,11 +2417,10 @@ WHERE t2.ugroup = t3_i.sys_id AND
t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND
t2.user = '86826bf03710200044e0bfc8bcbe5d79');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2
-1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where
+1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary
+1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
+1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index
-3 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where
-3 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
SELECT t1.assignment_group
FROM t1, t3
WHERE t1.assignment_group = t3.sys_id AND
@@ -2455,9 +2463,8 @@ alter table t1 add key(id);
explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
1
@@ -2506,20 +2513,17 @@ drop procedure prepare_data;
set @@optimizer_switch= @local_optimizer_switch;
drop table t1,t2,t3;
CREATE TABLE t1 ( id int NOT NULL, key(id));
-INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19);
+INSERT INTO t1 select seq from seq_11_to_39;
CREATE TABLE t2 (i1 int NOT NULL, i2 int NOT NULL);
-INSERT INTO t2 VALUES (11,11),(12,12),(13,13);
+INSERT INTO t2 select seq,seq+1 from seq_11_to_50;
CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2;
explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 index id id 4 NULL 29 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 40 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
1
-1
-1
-1
drop table t1,t2;
drop view v1;
#
@@ -2815,8 +2819,7 @@ SET @@optimizer_switch='default,semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where
+1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
pk
2
diff --git a/mysql-test/main/subselect_mat_cost.result b/mysql-test/main/subselect_mat_cost.result
index 9de70573189..d7ae095e1db 100644
--- a/mysql-test/main/subselect_mat_cost.result
+++ b/mysql-test/main/subselect_mat_cost.result
@@ -59,15 +59,15 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial
Q1.1m:
MATERIALIZATION: there are too many rows in the outer query
to be looked up in the inner table.
-set statement optimizer_cache_hit_ratio=20 for EXPLAIN
+EXPLAIN
SELECT count(*) FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where
-3 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
-set statement optimizer_cache_hit_ratio=20 for SELECT count(*) FROM Country
+2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
+SELECT count(*) FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 100000;
@@ -105,13 +105,25 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
(select Language from CountryLanguage where Percentage > 50) OR
City.name LIKE '%Island%');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Rowid-ordered scan
+1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where
-2 MATERIALIZED CountryLanguage range Percentage,Language Percentage 4 NULL 197 Using index condition; Rowid-ordered scan
+2 MATERIALIZED CountryLanguage ALL Percentage,Language NULL NULL NULL 984 Using where
+EXPLAIN
SELECT *
FROM Country, City
WHERE City.Country = Country.Code AND
-Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
+Country.SurfaceArea < 500 AND Country.SurfaceArea > 10 AND
+(City.Name IN
+(select Language from CountryLanguage where Percentage > 50) OR
+City.name LIKE '%Island%');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 32 Using index condition; Rowid-ordered scan
+1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where
+2 MATERIALIZED CountryLanguage ALL Percentage,Language NULL NULL NULL 984 Using where
+SELECT *
+FROM Country, City
+WHERE City.Country = Country.Code AND
+Country.SurfaceArea < 500 AND Country.SurfaceArea > 10 AND
(City.Name IN
(select Language from CountryLanguage where Percentage > 50) OR
City.name LIKE '%Island%');
@@ -130,7 +142,7 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
(select Language from CountryLanguage where Percentage > 50) OR
Country.name LIKE '%Island%');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Using where; Rowid-ordered scan
+1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
1 PRIMARY City ref Country Country 3 world.Country.Code 17
2 DEPENDENT SUBQUERY CountryLanguage index_subquery Percentage,Language Language 30 func 2 Using where
SELECT *
@@ -175,7 +187,7 @@ OR
(Country.Code, City.Name) IN
(select Country, Language from CountryLanguage));
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 73 Using index condition; Rowid-ordered scan
+1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where
3 MATERIALIZED CountryLanguage index PRIMARY,Language PRIMARY 33 NULL 984 Using index
2 DEPENDENT SUBQUERY CountryLanguage unique_subquery PRIMARY,Percentage,Language PRIMARY 33 func,func 1 Using where
@@ -487,9 +499,30 @@ FROM City JOIN Country ON City.Country = Country.Code
GROUP BY City.Name
HAVING City.Name IN (select Name from Country where population < 1000000);
id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY City ALL Country NULL NULL NULL 4079 Using temporary; Using filesort
+1 PRIMARY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using index
+2 MATERIALIZED Country ALL Name NULL NULL NULL 239 Using where
+Last_query_cost 5.934845
+EXPLAIN
+SELECT straight_join City.Name, City.Population
+FROM Country JOIN City ON City.Country = Country.Code
+GROUP BY City.Name
+HAVING City.Name IN (select Name from Country where population < 1000000);
+id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Country index PRIMARY PRIMARY 3 NULL 239 Using index; Using temporary; Using filesort
1 PRIMARY City ref Country Country 3 world.Country.Code 17
2 MATERIALIZED Country ALL Name NULL NULL NULL 239 Using where
+Last_query_cost 7.951232
+EXPLAIN
+SELECT City.Name, City.Population
+FROM Country LEFT JOIN City ON City.Country = Country.Code
+GROUP BY City.Name
+HAVING City.Name IN (select Name from Country where population < 1000000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY Country index NULL PRIMARY 3 NULL 239 Using index; Using temporary; Using filesort
+1 PRIMARY City ref Country Country 3 world.Country.Code 17
+2 MATERIALIZED Country ALL Name NULL NULL NULL 239 Using where
+Last_query_cost 7.951232
SELECT City.Name, City.Population
FROM City JOIN Country ON City.Country = Country.Code
GROUP BY City.Name
diff --git a/mysql-test/main/subselect_mat_cost.test b/mysql-test/main/subselect_mat_cost.test
index 6b7fa4fee64..60763076c45 100644
--- a/mysql-test/main/subselect_mat_cost.test
+++ b/mysql-test/main/subselect_mat_cost.test
@@ -73,13 +73,13 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial
-- echo Q1.1m:
-- echo MATERIALIZATION: there are too many rows in the outer query
-- echo to be looked up in the inner table.
-set statement optimizer_cache_hit_ratio=20 for EXPLAIN
+EXPLAIN
SELECT count(*) FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 100000;
-set statement optimizer_cache_hit_ratio=20 for SELECT count(*) FROM Country
+SELECT count(*) FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 100000;
@@ -113,10 +113,19 @@ SELECT *
(select Language from CountryLanguage where Percentage > 50) OR
City.name LIKE '%Island%');
+EXPLAIN
SELECT *
FROM Country, City
WHERE City.Country = Country.Code AND
- Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
+ Country.SurfaceArea < 500 AND Country.SurfaceArea > 10 AND
+ (City.Name IN
+ (select Language from CountryLanguage where Percentage > 50) OR
+ City.name LIKE '%Island%');
+
+SELECT *
+ FROM Country, City
+ WHERE City.Country = Country.Code AND
+ Country.SurfaceArea < 500 AND Country.SurfaceArea > 10 AND
(City.Name IN
(select Language from CountryLanguage where Percentage > 50) OR
City.name LIKE '%Island%');
@@ -374,12 +383,26 @@ SELECT City.Name, City.Population
FROM City JOIN Country ON City.Country = Country.Code
GROUP BY City.Name
HAVING City.Name IN (select Name from Country where population < 1000000);
+--source include/last_query_cost.inc
+EXPLAIN
+SELECT straight_join City.Name, City.Population
+FROM Country JOIN City ON City.Country = Country.Code
+GROUP BY City.Name
+HAVING City.Name IN (select Name from Country where population < 1000000);
+--source include/last_query_cost.inc
+
+EXPLAIN
SELECT City.Name, City.Population
-FROM City JOIN Country ON City.Country = Country.Code
+FROM Country LEFT JOIN City ON City.Country = Country.Code
GROUP BY City.Name
HAVING City.Name IN (select Name from Country where population < 1000000);
+--source include/last_query_cost.inc
+SELECT City.Name, City.Population
+FROM City JOIN Country ON City.Country = Country.Code
+GROUP BY City.Name
+HAVING City.Name IN (select Name from Country where population < 1000000);
-- echo
-- echo 5. Subqueries with UNION
diff --git a/mysql-test/main/subselect_mat_cost_bugs.result b/mysql-test/main/subselect_mat_cost_bugs.result
index 14522a24950..77b3430ba1f 100644
--- a/mysql-test/main/subselect_mat_cost_bugs.result
+++ b/mysql-test/main/subselect_mat_cost_bugs.result
@@ -95,9 +95,9 @@ t1a ON (t1a.c2 = t1b.pk AND 2)
WHERE t1.pk) ;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9 100.00 Using where
-2 DEPENDENT SUBQUERY t1b ALL NULL NULL NULL NULL 9 100.00
+2 DEPENDENT SUBQUERY t1b ALL NULL NULL NULL NULL 9 100.00 Using where
2 DEPENDENT SUBQUERY t1a ref c2 c2 5 test.t1b.pk 1 100.00 Using where
-2 DEPENDENT SUBQUERY t2 index c3 c3 9 NULL 2 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 ref c3 c3 4 test.t1b.c4 1 100.00 Using index
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <expr_cache><`test`.`t1`.`c1`,`test`.`t1`.`pk`>(<in_optimizer>(`test`.`t1`.`c1`,<exists>(/* select#2 */ select `test`.`t1a`.`c1` from `test`.`t1b` join `test`.`t2` left join `test`.`t1a` on(`test`.`t1a`.`c2` = `test`.`t1b`.`pk` and 2) where `test`.`t2`.`c3` = `test`.`t1b`.`c4` and `test`.`t1`.`pk` <> 0 and <cache>(`test`.`t1`.`c1`) = `test`.`t1a`.`c1`)))
@@ -196,8 +196,8 @@ ORDER BY field1 ;
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 alias1 eq_ref PRIMARY PRIMARY 4 alias2.f3 1 Using index
-3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2
-3 DEPENDENT SUBQUERY t1 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+3 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index
+3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
2 DERIVED t2 ALL NULL NULL NULL NULL 2
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
@@ -263,8 +263,8 @@ WHERE alias1.f11 OR alias1.f3 = 50 AND alias1.f10
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-2 MATERIALIZED alias1 ALL NULL NULL NULL NULL 2 Using where
-2 MATERIALIZED alias2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY alias1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY alias2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t2
WHERE ( f12 ) IN (
SELECT alias2.f3
@@ -275,6 +275,8 @@ f12 f13
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
+Warning 1292 Truncated incorrect DECIMAL value: 'f'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
EXPLAIN
SELECT * FROM t2
WHERE ( f12 ) IN (
@@ -283,8 +285,8 @@ FROM t1 AS alias1, t1 AS alias2
WHERE (alias2.f10 = alias1.f11) AND (alias1.f11 OR alias1.f3 = 50 AND alias1.f10));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-2 MATERIALIZED alias1 ALL NULL NULL NULL NULL 2 Using where
-2 MATERIALIZED alias2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY alias1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY alias2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t2
WHERE ( f12 ) IN (
SELECT alias2.f3
@@ -294,6 +296,8 @@ f12 f13
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'f'
Warning 1292 Truncated incorrect DECIMAL value: 'd'
+Warning 1292 Truncated incorrect DECIMAL value: 'f'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
set @@optimizer_switch=@save_optimizer_switch;
drop table t1, t2;
#
@@ -316,7 +320,7 @@ explain
select c1 from t1 where c1 in (select kp1 from t2 where kp2 = 10 and c2 = 4) or c1 > 7;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
-2 DEPENDENT SUBQUERY t2 ref key1,key2,key3 key3 5 const 1 Using where
+2 DEPENDENT SUBQUERY t2 index_subquery key1,key2,key3 key1 10 func,const 1 Using where
select c1 from t1 where c1 in (select kp1 from t2 where kp2 = 10 and c2 = 4) or c1 > 7;
c1
set @@optimizer_switch='default';
@@ -363,8 +367,8 @@ WHERE t4.a >= t3.b
AND a = SOME (SELECT b FROM t5));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY t4 ALL PRIMARY NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary; End temporary; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary
+2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t5.b 1 Using where; End temporary
SELECT *
FROM t3
WHERE t3.b > ALL (
diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result
index 87283487ef1..9076f05fc08 100644
--- a/mysql-test/main/subselect_no_exists_to_in.result
+++ b/mysql-test/main/subselect_no_exists_to_in.result
@@ -1433,6 +1433,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1479,42 +1482,48 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
+explain extended select * from t2 where t2.a in (select a from t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using index; FirstMatch(t2)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select a from t1);
a
2
3
4
-explain extended select * from t2 where t2.a in (select a from t1);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 0.29 Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
-explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
-insert into t1 values (3,31);
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1524,12 +1533,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
-Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1591,6 +1594,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1618,21 +1624,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2424,21 +2430,22 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
-2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 25 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(/* select#2 */ select 1 from `test`.`t1` where `test`.`t1`.`a` = `test`.`up`.`a` limit 1))
+Note 1003 /* select#1 */ select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(/* select#2 */ select 1 from `test`.`t1` where `test`.`t1`.`a` = `test`.`up`.`a` limit 1))
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -3106,6 +3113,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3121,7 +3132,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3133,7 +3144,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4233,8 +4244,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4335,6 +4346,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -4396,8 +4410,8 @@ CREATE INDEX I1 ON t1 (a);
CREATE INDEX I2 ON t1 (b);
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
a b
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
@@ -4406,15 +4420,15 @@ CREATE INDEX I1 ON t2 (a);
CREATE INDEX I2 ON t2 (b);
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t2 index I1 I1 4 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t2 ref I2 I2 13 test.t2.a 2 Using index condition
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
a b
EXPLAIN
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
a b
DROP TABLE t1,t2;
@@ -5709,6 +5723,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5718,7 +5733,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 502 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5728,7 +5743,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
+2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 58 Using index
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
@@ -5745,9 +5760,9 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3
-1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index
-1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(it)
+1 PRIMARY it index PRIMARY PRIMARY 4 NULL 3 Using index
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.it.pk 1
+1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
pk i
11 0
diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result
index d7664b576b6..ad5ead75ccb 100644
--- a/mysql-test/main/subselect_no_mat.result
+++ b/mysql-test/main/subselect_no_mat.result
@@ -352,7 +352,7 @@ patient_uq clinic_uq
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t7 index PRIMARY PRIMARY 4 NULL 2 100.00 Using index
-1 PRIMARY t6 ALL i1 NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t6 ref i1 i1 5 test.t7.uq 2 100.00
Warnings:
Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t7` join `test`.`t6` where `test`.`t6`.`clinic_uq` = `test`.`t7`.`uq`
@@ -1436,6 +1436,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1482,42 +1485,48 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
+explain extended select * from t2 where t2.a in (select a from t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using index; FirstMatch(t2)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select a from t1);
a
2
3
4
-explain extended select * from t2 where t2.a in (select a from t1);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 0.29 Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
-explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
-insert into t1 values (3,31);
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1527,12 +1536,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
-Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1594,6 +1597,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1621,21 +1627,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2427,21 +2433,22 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join)
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 25 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`up`.`a`
+Note 1003 select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`up`.`a`
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -2992,7 +2999,7 @@ Note 1003 /* select#1 */ select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 9 11.11 Using where; Start temporary; End temporary
Warnings:
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`flag` = 'N' and `test`.`t2`.`one` = `test`.`t1`.`one` and `test`.`t2`.`two` = `test`.`t1`.`two`
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
@@ -3108,6 +3115,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3123,7 +3134,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3135,7 +3146,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4335,6 +4346,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -4396,8 +4410,8 @@ CREATE INDEX I1 ON t1 (a);
CREATE INDEX I2 ON t1 (b);
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
a b
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
@@ -4406,15 +4420,15 @@ CREATE INDEX I1 ON t2 (a);
CREATE INDEX I2 ON t2 (b);
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t2 index I1 I1 4 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t2 ref I2 I2 13 test.t2.a 2 Using index condition
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
a b
EXPLAIN
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
a b
DROP TABLE t1,t2;
@@ -5695,9 +5709,9 @@ WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
FROM it2,it3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot1 ALL NULL NULL NULL NULL 2
-1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using join buffer (flat, BNL join)
-1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where
-1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using where; FirstMatch(ot4)
+1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
+1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
@@ -5706,6 +5720,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5715,7 +5730,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
-1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 502 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5725,7 +5740,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
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 t2 ref idx idx 5 test.t1.a 2 Using index; FirstMatch(t1)
+1 PRIMARY t2 ref idx idx 5 test.t1.a 11 Using index; FirstMatch(t1)
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
@@ -5742,9 +5757,9 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3
-1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index
-1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(it)
+1 PRIMARY it index PRIMARY PRIMARY 4 NULL 3 Using index
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.it.pk 1
+1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
pk i
11 0
diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result
index 4e36ab903b3..1d51bd6b976 100644
--- a/mysql-test/main/subselect_no_opts.result
+++ b/mysql-test/main/subselect_no_opts.result
@@ -1432,6 +1432,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1478,23 +1481,19 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
-select * from t2 where t2.a in (select a from t1);
-a
-2
-3
-4
explain extended select * from t2 where t2.a in (select a from t1);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a)))
-select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+select * from t2 where t2.a in (select a from t1);
a
2
+3
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -1502,18 +1501,28 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
-select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
-3
+4
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref a a 5 func 1001 100.00 Using index
-2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 66.67 Using where; Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))
+select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+a
+2
+3
insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
+Warnings:
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1523,12 +1532,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
-Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1590,6 +1593,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1617,21 +1623,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2423,21 +2429,22 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
-2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 25 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <in_optimizer>(`test`.`up`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where <cache>(`test`.`up`.`a`) = `test`.`t1`.`a`))
+Note 1003 /* select#1 */ select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` where <in_optimizer>(`test`.`up`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where <cache>(`test`.`up`.`a`) = `test`.`t1`.`a`))
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -3104,6 +3111,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3119,7 +3130,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3131,7 +3142,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4229,8 +4240,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4331,6 +4342,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -5702,6 +5716,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5711,7 +5726,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 502 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5721,7 +5736,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 DEPENDENT SUBQUERY t2 index_subquery idx idx 5 func 2 Using index
+2 DEPENDENT SUBQUERY t2 index_subquery idx idx 5 func 58 Using index
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result
index 8635f5352f1..18be05fe527 100644
--- a/mysql-test/main/subselect_no_scache.result
+++ b/mysql-test/main/subselect_no_scache.result
@@ -351,7 +351,7 @@ patient_uq clinic_uq
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t7 index PRIMARY PRIMARY 4 NULL 2 100.00 Using index
-1 PRIMARY t6 ALL i1 NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t6 ref i1 i1 5 test.t7.uq 2 100.00
Warnings:
Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t7` join `test`.`t6` where `test`.`t6`.`clinic_uq` = `test`.`t7`.`uq`
@@ -1435,6 +1435,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1481,42 +1484,48 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
+explain extended select * from t2 where t2.a in (select a from t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using index; FirstMatch(t2)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select a from t1);
a
2
3
4
-explain extended select * from t2 where t2.a in (select a from t1);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 0.29 Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
-explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
+1 PRIMARY t1 ref a a 5 test.t2.a 101 0.99 Using where; Using index; FirstMatch(t2)
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
-insert into t1 values (3,31);
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1526,12 +1535,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2)
-Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1593,6 +1596,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1620,21 +1626,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2426,22 +2432,23 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 25 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
+Note 1003 select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -3109,6 +3116,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3124,7 +3135,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3136,7 +3147,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4236,8 +4247,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4338,6 +4349,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -4399,8 +4413,8 @@ CREATE INDEX I1 ON t1 (a);
CREATE INDEX I2 ON t1 (b);
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
a b
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
@@ -4409,15 +4423,15 @@ CREATE INDEX I1 ON t2 (a);
CREATE INDEX I2 ON t2 (b);
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t2 index I1 I1 4 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t2 ref I2 I2 13 test.t2.a 2 Using index condition
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
a b
EXPLAIN
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where
-1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1)
+1 PRIMARY t1 index I1 I1 2 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t1 ref I2 I2 13 test.t1.a 2 Using index condition
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
a b
DROP TABLE t1,t2;
@@ -4462,11 +4476,10 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 select 2 AS `2` from `test`.`t1` semi join (`test`.`t2`) where 1
+Note 1003 select 2 AS `2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`a`
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
@@ -5713,6 +5726,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5723,7 +5737,7 @@ WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 502
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5733,7 +5747,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
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 t2 ref idx idx 5 test.t1.a 2 Using index; FirstMatch(t1)
+1 PRIMARY t2 ref idx idx 5 test.t1.a 11 Using index; FirstMatch(t1)
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
@@ -5750,9 +5764,9 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3
-1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index
-1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(it)
+1 PRIMARY it index PRIMARY PRIMARY 4 NULL 3 Using index
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.it.pk 1
+1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
pk i
11 0
diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result
index cca7f431d0e..07eb361b91c 100644
--- a/mysql-test/main/subselect_no_semijoin.result
+++ b/mysql-test/main/subselect_no_semijoin.result
@@ -914,9 +914,9 @@ a t1.a in (select t2.a from t2)
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
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
-2 MATERIALIZED t2 index a a 5 NULL 3 100.00 Using index
+2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having `test`.`t2`.`a` is null)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
CREATE TABLE t3 (a int(11) default '0');
INSERT INTO t3 VALUES (1),(2),(3);
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
@@ -928,8 +928,8 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
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
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00
-2 MATERIALIZED t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00 Using where
+2 MATERIALIZED t2 ref a a 5 test.t3.a 2 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
drop table t1,t2,t3;
@@ -1432,6 +1432,9 @@ drop table if exists t1;
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
a
1
+#
+# IN subselect optimization test
+#
create table t1 (a int not null, b int, primary key (a));
create table t2 (a int not null, primary key (a));
create table t3 (a int not null, b int, primary key (a));
@@ -1456,9 +1459,9 @@ a
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
-2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using where
Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`b` <> 30 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`a`))))
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on PRIMARY where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
@@ -1466,10 +1469,10 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
-2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
-2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
+2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where
+2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`a`))))
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
drop table t1, t2, t3;
create table t1 (a int, b int, index a (a,b));
create table t2 (a int, index a (a));
@@ -1478,23 +1481,19 @@ insert into t1 values (1,10), (2,20), (3,30), (4,40);
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
insert into t1
-select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+select rand()*100000+200,rand(1)*100000 from t0 A, t0 B, t0 C, t0 D;
insert into t2 values (2), (3), (4), (5);
insert into t3 values (10,3), (20,4), (30,5);
-select * from t2 where t2.a in (select a from t1);
-a
-2
-3
-4
explain extended select * from t2 where t2.a in (select a from t1);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a))))
-select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+select * from t2 where t2.a in (select a from t1);
a
2
+3
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -1502,18 +1501,28 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
-select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
-3
+4
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref a a 5 func 1001 100.00 Using index
-2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 66.67 Using where; Using index; Using join buffer (flat, BNL join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
+select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
+a
+2
+3
insert into t1 values (3,31);
+explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
+Warnings:
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
2
@@ -1523,12 +1532,6 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31
a
2
4
-explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index NULL a 5 NULL 4 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 100.00 Using index; Using where
-Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where `test`.`t1`.`b` <> 30 and <cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
drop table t0, t1, t2, t3;
create table t1 (a int, b int);
create table t2 (a int, b int);
@@ -1590,6 +1593,9 @@ Note 1003 (select 'tttt' AS `s1` from dual)
s1
tttt
drop table t1;
+#
+# IN optimisation test results
+#
create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
@@ -1617,27 +1623,27 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 MATERIALIZED t2 range s1 s1 6 NULL 1 100.00 Using where; Using index
+2 SUBQUERY t2 index_subquery s1 s1 6 func 2 50.00 Using index; Using where; Full scan on NULL key
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,`test`.`t1`.`s1` in ( <materialize> (/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where `test`.`t2`.`s1` < 'a2' ), <primary_index_lookup>(`test`.`t1`.`s1` in <temporary table> on distinct_key where `test`.`t1`.`s1` = `<subquery2>`.`s1`)))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where `test`.`t2`.`s1` < 'a2' having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
drop table t1,t2;
create table t2 (a int, b int not null);
create table t3 (a int);
@@ -1890,9 +1896,9 @@ id text
explain extended select * from t1 where id not in (select id from t1 where id < 8);
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 Using where
-2 MATERIALIZED t1 range PRIMARY PRIMARY 4 NULL 7 100.00 Using where; Using index
+2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where !<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (/* select#2 */ select `test`.`t1`.`id` from `test`.`t1` where `test`.`t1`.`id` < 8 ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on distinct_key where `test`.`t1`.`id` = `<subquery2>`.`id`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where !<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where `test`.`t1`.`id` < 8 and <cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`))))
explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
@@ -2423,21 +2429,22 @@ a
1
3
DROP TABLE t1;
+#
+# SELECT(EXISTS * ...)optimisation
+#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(5,6),(7,8);
-select * from t1 up where exists (select * from t1 where t1.a=up.a);
-a b
-1 2
-3 4
-5 6
-7 8
-explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
+insert into t1 select seq,seq from seq_20_to_40;
+select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
+sum(a+b)
+1296
+explain extended select sum(a+b) from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 25 100.00 Using where
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 25 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(<in_optimizer>(`test`.`up`.`a`,`test`.`up`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`up`.`a` in <temporary table> on distinct_key where `test`.`up`.`a` = `<subquery2>`.`a`))))
+Note 1003 /* select#1 */ select sum(`test`.`up`.`a` + `test`.`up`.`b`) AS `sum(a+b)` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(<in_optimizer>(`test`.`up`.`a`,`test`.`up`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`up`.`a` in <temporary table> on distinct_key where `test`.`up`.`a` = `<subquery2>`.`a`))))
drop table t1;
CREATE TABLE t1 (t1_a int);
INSERT INTO t1 VALUES (1);
@@ -3104,6 +3111,10 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+#
+# Bug#21180 Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
@@ -3119,7 +3130,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3131,7 +3142,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
+2 SUBQUERY t2 range cb cb 40 NULL 3 Using index condition
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4229,8 +4240,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4331,6 +4342,9 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
+#
+# Bug#28076 inconsistent binary/varbinary comparison
+#
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
@@ -4623,7 +4637,7 @@ WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
ORDER BY outr.pk;
id select_type table type possible_keys key key_len ref rows Extra
x x outr ALL x x x x x x
-x x t1 index x x x x x x
+x x t1 eq_ref x x x x x x
x x t2 index x x x x x x
# should not crash on debug binaries
SELECT * FROM t2 outr
@@ -5702,6 +5716,7 @@ CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL),(1000);
+insert into t2 select seq from seq_3_to_500;
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
@@ -5711,7 +5726,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 502
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
@@ -5721,7 +5736,7 @@ SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
-2 DEPENDENT SUBQUERY t2 index_subquery idx idx 5 func 2 Using index
+2 DEPENDENT SUBQUERY t2 index_subquery idx idx 5 func 58 Using index
DROP TABLE t1,t2;
#
# BUG#752992: Wrong results for a subquery with 'semijoin=on'
diff --git a/mysql-test/main/subselect_partial_match.result b/mysql-test/main/subselect_partial_match.result
index 3d10e912f22..16a487445e4 100644
--- a/mysql-test/main/subselect_partial_match.result
+++ b/mysql-test/main/subselect_partial_match.result
@@ -763,6 +763,7 @@ CREATE TABLE t1 (a1 int DEFAULT NULL, a2 int DEFAULT NULL);
INSERT INTO t1 VALUES (NULL,2), (4,NULL),(100,100);
CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
INSERT INTO t2 VALUES (6,NULL), (NULL,0),(1000,1000);
+insert into t2 select seq,seq from seq_2000_to_2100;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on';
set @tmp_optimizer_switch=@@optimizer_switch;
set optimizer_switch='derived_merge=off,derived_with_keys=off';
@@ -771,7 +772,7 @@ SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
+3 MATERIALIZED t2 ALL NULL NULL NULL NULL 104 100.00
Warnings:
Note 1003 /* select#1 */ select `table1`.`a1` AS `a1`,`table1`.`a2` AS `a2` from (/* select#2 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where !(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (/* select#3 */ select `test`.`t2`.`b2` from `test`.`t2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery3>`.`b2`))))) `table1`
set optimizer_switch=@tmp_optimizer_switch;
@@ -780,12 +781,13 @@ DROP TABLE t1, t2;
# LP BUG#613009 Crash in Ordered_key::get_field_idx
#
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=off';
-create table t1 (a1 char(3) DEFAULT NULL, a2 char(3) DEFAULT NULL);
+create table t1 (a1 char(4) DEFAULT NULL, a2 char(4) DEFAULT NULL);
insert into t1 values (NULL, 'a21'), (NULL, 'a22'), ('xxx','xxx');
+insert into t1 select seq,seq from seq_2000_to_2100;
explain select * from t1 where (a1, a2) not in (select a1, a2 from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY t1 ALL NULL NULL NULL NULL 104 Using where
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 104
select * from t1 where (a1, a2) not in (select a1, a2 from t1);
a1 a2
drop table t1;
diff --git a/mysql-test/main/subselect_partial_match.test b/mysql-test/main/subselect_partial_match.test
index 8fdd5e451ba..9a32ef5491c 100644
--- a/mysql-test/main/subselect_partial_match.test
+++ b/mysql-test/main/subselect_partial_match.test
@@ -2,6 +2,7 @@
# Tests for
# MWL#68: Subquery optimization: Efficient NOT IN execution with NULLs
#
+--source include/have_sequence.inc
set @save_optimizer_switch=@@optimizer_switch;
@@ -618,6 +619,8 @@ INSERT INTO t1 VALUES (NULL,2), (4,NULL),(100,100);
CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
INSERT INTO t2 VALUES (6,NULL), (NULL,0),(1000,1000);
+insert into t2 select seq,seq from seq_2000_to_2100;
+
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on';
set @tmp_optimizer_switch=@@optimizer_switch;
@@ -634,8 +637,9 @@ DROP TABLE t1, t2;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=off';
-create table t1 (a1 char(3) DEFAULT NULL, a2 char(3) DEFAULT NULL);
+create table t1 (a1 char(4) DEFAULT NULL, a2 char(4) DEFAULT NULL);
insert into t1 values (NULL, 'a21'), (NULL, 'a22'), ('xxx','xxx');
+insert into t1 select seq,seq from seq_2000_to_2100;
explain select * from t1 where (a1, a2) not in (select a1, a2 from t1);
select * from t1 where (a1, a2) not in (select a1, a2 from t1);
drop table t1;
diff --git a/mysql-test/main/subselect_sj.result b/mysql-test/main/subselect_sj.result
index 55fb1bfe367..a6905d5d819 100644
--- a/mysql-test/main/subselect_sj.result
+++ b/mysql-test/main/subselect_sj.result
@@ -76,19 +76,19 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t12` join `test`.`t1` where `test`.`t12`.`pk` = `test`.`t10`.`a` and `test`.`t10`.`pk` = `test`.`t1`.`a`
subqueries within outer joins go into ON expr.
-explAin extended
+explain extended
select * from t1 left join (t2 A, t2 B) on ( A.A= t1.A And B.A in (select pk from t10));
-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 A ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY B ALL NULL NULL NULL NULL 3 100.00 Using where
-2 MATERIALIZED t10 index PRIMARY PRIMARY 4 NULL 10 100.00 Using index
+2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(`test`.`A`.`A` = `test`.`t1`.`A` And <in_optimizer>(`test`.`B`.`A`,`test`.`B`.`A` in ( <mAteriAlize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` ), <primAry_index_lookup>(`test`.`B`.`A` in <temporAry tABle> on distinct_key where `test`.`B`.`A` = `<suBquery2>`.`pk`)))) where 1
+Note 1003 /* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(`test`.`A`.`A` = `test`.`t1`.`A` And <in_optimizer>(`test`.`B`.`A`,<exists>(<primAry_index_lookup>(<cAche>(`test`.`B`.`A`) in t10 on PRIMARY)))) where 1
t2 should be wrapped into OJ-nest, so we have "t1 LJ (t2 J t10)"
-explAin extended
+explain extended
select * from t1 left join t2 on (t2.A= t1.A And t2.A in (select pk from t10));
-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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
@@ -344,8 +344,8 @@ WHERE PNUM IN
(SELECT PNUM FROM PROJ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY STAFF ALL NULL NULL NULL NULL 5
-1 PRIMARY PROJ ALL NULL NULL NULL NULL 6
-1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF)
+1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary
+1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary
SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@@ -502,7 +502,7 @@ EXPLAIN EXTENDED SELECT vkey FROM t0 WHERE pk IN
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t0 ALL PRIMARY NULL NULL NULL 5 100.00
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t0.pk 1 100.00 Using where
-1 PRIMARY t2 ref vkey vkey 4 test.t1.vnokey 2 100.00 Using index; FirstMatch(t1)
+1 PRIMARY t2 ref vkey vkey 4 test.t1.vnokey 2 50.00 Using index; FirstMatch(t1)
Warnings:
Note 1003 select `test`.`t0`.`vkey` AS `vkey` from `test`.`t0` `t1` semi join (`test`.`t0` `t2`) join `test`.`t0` where `test`.`t1`.`pk` = `test`.`t0`.`pk` and `test`.`t2`.`vkey` = `test`.`t1`.`vnokey`
SELECT vkey FROM t0 WHERE pk IN
@@ -763,16 +763,16 @@ explain extended
select a from t1
where a in (select c from t2 where d >= some(select e from t3 where b=e));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Start temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 16.67 Using where; End temporary; Using join buffer (flat, BNL join)
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
show warnings;
Level Code Message
Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
select a from t1
where a in (select c from t2 where d >= some(select e from t3 where b=e));
a
@@ -806,10 +806,9 @@ insert into t2 (pk) values (-1),(0);
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
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 <subquery2> eq_ref distinct_key distinct_key 11 func,func 1 100.00
-2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan
+1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan; FirstMatch(t1)
Warnings:
-Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`pk` > 0
+Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t2`.`b` = `test`.`t1`.`b` and `test`.`t2`.`pk` > 0
SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
pk
2
@@ -1999,7 +1998,7 @@ explain extended
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
-1 PRIMARY t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t4 ref_or_null f2 f2 5 const 4 25.00 Using where; Using index; FirstMatch(t2)
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
@@ -2155,8 +2154,8 @@ explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
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 t3 ref b b 5 test.t1.b 2 Start temporary
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ref b b 5 test.t1.b 2 Using where; Start temporary
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using index; End temporary
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
5 6
@@ -2179,10 +2178,10 @@ INSERT INTO t5 VALUES (7,0),(9,0);
explain
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; Start temporary
1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where
-1 PRIMARY t4 ALL NULL NULL NULL NULL 3 FirstMatch(t5)
-1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3
+1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
a
0
@@ -2261,10 +2260,10 @@ alias1.c IN (SELECT SQ3_alias1.b
FROM t2 AS SQ3_alias1 STRAIGHT_JOIN t2 AS SQ3_alias2)
LIMIT 100;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20
-1 PRIMARY alias2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
+1 PRIMARY alias2 ALL NULL NULL NULL NULL 20
1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
-1 PRIMARY SQ3_alias1 ALL NULL NULL NULL NULL 20 Using where; Start temporary
+1 PRIMARY SQ3_alias1 ALL NULL NULL NULL NULL 20 Start temporary
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
1 PRIMARY SQ3_alias2 index NULL PRIMARY 4 NULL 20 Using index; End temporary
2 DERIVED t2 ALL NULL NULL NULL NULL 20
create table t3 as
@@ -2437,9 +2436,9 @@ SET SESSION optimizer_switch='loosescan=off';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index idx idx 9 NULL 2 Using where; Using index; Start temporary
-1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY t2 range idx idx 4 NULL 2 Using where; Using index
+1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
a
5
@@ -2447,9 +2446,9 @@ SET SESSION optimizer_switch='loosescan=on';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index idx idx 9 NULL 2 Using where; Using index; Start temporary
-1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY t2 range idx idx 4 NULL 2 Using where; Using index
+1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
a
5
@@ -2576,7 +2575,7 @@ WHERE ( b, d ) IN
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary
1 PRIMARY t2 ref c c 5 test.t1.b 1
-1 PRIMARY t1 ref b b 5 test.t1.b 2
+1 PRIMARY t1 ALL b NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
@@ -2768,8 +2767,8 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where
-1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary
-1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary
+1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11
+1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2)
3 DERIVED t1 ALL NULL NULL NULL NULL 11
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
@@ -3037,7 +3036,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5 100.00 Start temporary
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where; End temporary
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 10.00 Using where; End temporary
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1`,'x' AS `c2` from `test`.`t1` semi join (`test`.`t1` left join `test`.`t3` on(`test`.`t1`.`c1` = `test`.`t3`.`c3`)) where `test`.`t1`.`pk` = `test`.`t1`.`pk` order by 'x',`test`.`t1`.`c1`
DROP TABLE t1,t2,t3;
@@ -3289,7 +3288,7 @@ explain extended
SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00
-1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ref col1 col1 5 const 2 50.00 Using index condition; Using where; FirstMatch(t1)
Warnings:
Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null
DROP TABLE t1, t2;
diff --git a/mysql-test/main/subselect_sj.test b/mysql-test/main/subselect_sj.test
index 4d35b4f0839..ed2d7c99ec2 100644
--- a/mysql-test/main/subselect_sj.test
+++ b/mysql-test/main/subselect_sj.test
@@ -70,13 +70,13 @@ explain extended select * from t1 where a in (select t10.pk from t10, t12 where
--echo subqueries within outer joins go into ON expr.
# TODO: psergey: check if case conversions like those are ok (it broke on windows)
---replace_result a A b B
+--replace_result a A b B explain explain table table possible possible
explain extended
select * from t1 left join (t2 A, t2 B) on ( A.a= t1.a and B.a in (select pk from t10));
# TODO: psergey: check if case conversions like those are ok (it broke on windows)
--echo t2 should be wrapped into OJ-nest, so we have "t1 LJ (t2 J t10)"
---replace_result a A b B
+--replace_result a A b B explain explain table table possible possible
explain extended
select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10));
diff --git a/mysql-test/main/subselect_sj2.result b/mysql-test/main/subselect_sj2.result
index 728014d0202..0a8a680adc0 100644
--- a/mysql-test/main/subselect_sj2.result
+++ b/mysql-test/main/subselect_sj2.result
@@ -25,11 +25,7 @@ key(b)
);
insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
-select * from t1;
-a b
-1 1
-1 1
-2 2
+insert into t1 values (1030,30),(1031,31),(1032,32),(1033,33);
select * from t2;
a b
0 0
@@ -54,9 +50,9 @@ a b
19 14
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t2 ref b b 5 test.t1.a 2
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t2 ALL b NULL NULL NULL 20
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 7
select * from t2 where b in (select a from t1);
a b
1 1
@@ -82,9 +78,9 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t3 ref b b 5 test.t1.a 2
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t3 ALL b NULL NULL NULL 20
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 7
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -112,9 +108,8 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL #
-1 PRIMARY t3 ref b b 5 test.t0.a #
-2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t0 ALL NULL NULL NULL NULL # Using where; Start temporary
+1 PRIMARY t3 ref b b 5 test.t0.a # End temporary
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
a b pk1 pk2
0 0 0 0
@@ -135,19 +130,17 @@ set join_buffer_size= @save_join_buffer_size;
set max_heap_table_size= @save_max_heap_table_size;
explain select * from t1 where a in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where
1 PRIMARY t2 ref b b 5 test.t1.a 1 Using index; FirstMatch(t1)
-select * from t1;
-a b
-1 1
-1 1
-2 2
select * from t1 where a in (select b from t2);
a b
1 1
1 1
2 2
drop table t1, t2, t3;
+#
+# Test join buffering
+#
set @save_join_buffer_size = @@join_buffer_size;
set join_buffer_size= 8192;
create table t1 (a int, filler1 binary(200), filler2 binary(200));
@@ -307,7 +300,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -348,7 +341,7 @@ WHERE Language='English' AND Percentage > 10 AND
t2.Population > 100000);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 range Population,Country Population 4 NULL 1 Using index condition; Rowid-ordered scan; Start temporary
-1 PRIMARY t2 eq_ref PRIMARY,Population PRIMARY 3 test.t1.Country 1 Using where; End temporary
+1 PRIMARY t2 eq_ref|filter PRIMARY,Population PRIMARY|Population 3|4 test.t1.Country 1 (75%) Using where; End temporary; Using rowid filter
1 PRIMARY t3 eq_ref PRIMARY,Percentage PRIMARY 33 test.t1.Country,const 1 Using index condition; Using where
set optimizer_switch=@bug35674_save_optimizer_switch;
DROP TABLE t1,t2,t3;
@@ -840,9 +833,9 @@ explain
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index
+1 PRIMARY alias1 const PRIMARY PRIMARY 4 const #
1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan
-1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2)
+1 PRIMARY t1 ALL NULL NULL NULL NULL # FirstMatch(alias2)
1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
@@ -1235,10 +1228,10 @@ t1_pk1 t1_pk2 t3_i t3_c
explain
SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' );
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
+1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
-1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t3)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
@@ -1356,9 +1349,9 @@ WHERE
T3_0_.t3idref= 1
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary
+1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Start temporary
1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1
-1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index
+1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1
1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary
drop table t3,t2,t1;
set optimizer_search_depth=@tmp7474;
diff --git a/mysql-test/main/subselect_sj2.test b/mysql-test/main/subselect_sj2.test
index 7601dc3a730..4ccdcc50a38 100644
--- a/mysql-test/main/subselect_sj2.test
+++ b/mysql-test/main/subselect_sj2.test
@@ -2,13 +2,15 @@
# DuplicateElimination strategy test
#
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
set @innodb_stats_persistent_save= @@innodb_stats_persistent;
set @innodb_stats_persistent_sample_pages_save=
@@innodb_stats_persistent_sample_pages;
set global innodb_stats_persistent= 1;
set global innodb_stats_persistent_sample_pages=100;
---source include/have_innodb.inc
set @subselect_sj2_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
@@ -48,7 +50,7 @@ create table t2 (
insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
-select * from t1;
+insert into t1 values (1030,30),(1031,31),(1032,32),(1033,33);
select * from t2;
explain select * from t2 where b in (select a from t1);
select * from t2 where b in (select a from t1);
@@ -97,15 +99,15 @@ set max_heap_table_size= @save_max_heap_table_size;
# O2I join orders, with shortcutting:
explain select * from t1 where a in (select b from t2);
-select * from t1;
select * from t1 where a in (select b from t2);
drop table t1, t2, t3;
# (no need for anything in range/index_merge/DS-MRR)
-#
-# Test join buffering
-#
+--echo #
+--echo # Test join buffering
+--echo #
+
set @save_join_buffer_size = @@join_buffer_size;
set join_buffer_size= 8192;
@@ -256,6 +258,7 @@ INSERT INTO t3 VALUES
# Disable materialization to avoid races between query plans
set @bug35674_save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='materialization=off';
+
EXPLAIN
SELECT Name FROM t2
WHERE t2.Code IN (SELECT Country FROM t1 WHERE Population > 5000000)
diff --git a/mysql-test/main/subselect_sj2_jcl6.result b/mysql-test/main/subselect_sj2_jcl6.result
index 94eebd167f1..c3e3a77c679 100644
--- a/mysql-test/main/subselect_sj2_jcl6.result
+++ b/mysql-test/main/subselect_sj2_jcl6.result
@@ -36,11 +36,7 @@ key(b)
);
insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
-select * from t1;
-a b
-1 1
-1 1
-2 2
+insert into t1 values (1030,30),(1031,31),(1032,32),(1033,33);
select * from t2;
a b
0 0
@@ -66,7 +62,7 @@ a b
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL b NULL NULL NULL 20
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
select * from t2 where b in (select a from t1);
a b
1 1
@@ -92,9 +88,8 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t3 ref b b 5 test.t1.a 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t3 ALL b NULL NULL NULL 20
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where; FirstMatch(t3); Using join buffer (flat, BNL join)
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -122,9 +117,8 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL #
-1 PRIMARY t3 ref b b 5 test.t0.a # Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t0 ALL NULL NULL NULL NULL # Using where; Start temporary
+1 PRIMARY t3 ref b b 5 test.t0.a # End temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
a b pk1 pk2
0 0 0 0
@@ -145,19 +139,17 @@ set join_buffer_size= @save_join_buffer_size;
set max_heap_table_size= @save_max_heap_table_size;
explain select * from t1 where a in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where
1 PRIMARY t2 ref b b 5 test.t1.a 1 Using index; FirstMatch(t1)
-select * from t1;
-a b
-1 1
-1 1
-2 2
select * from t1 where a in (select b from t2);
a b
1 1
1 1
2 2
drop table t1, t2, t3;
+#
+# Test join buffering
+#
set @save_join_buffer_size = @@join_buffer_size;
set join_buffer_size= 8192;
create table t1 (a int, filler1 binary(200), filler2 binary(200));
@@ -174,8 +166,7 @@ a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
from t1 ot where a in (select a from t2 it);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot ALL NULL NULL NULL NULL 32
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED it ALL NULL NULL NULL NULL 22
+1 PRIMARY it ALL NULL NULL NULL NULL 22 Using where; FirstMatch(ot); Using join buffer (flat, BNL join)
select
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
from t1 ot where a in (select a from t2 it);
@@ -199,16 +190,15 @@ a mid(filler1, 1,10) Z
16 filler1234 1
17 filler1234 1
18 filler1234 1
-19 filler1234 1
2 duplicate 1
18 duplicate 1
+19 filler1234 1
explain select
a, mid(filler1, 1,10), length(filler1)=length(filler2)
from t2 ot where a in (select a from t1 it);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot ALL NULL NULL NULL NULL 22
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED it ALL NULL NULL NULL NULL 32
+1 PRIMARY it ALL NULL NULL NULL NULL 32 Using where; FirstMatch(ot); Using join buffer (flat, BNL join)
select
a, mid(filler1, 1,10), length(filler1)=length(filler2)
from t2 ot where a in (select a from t1 it);
@@ -232,8 +222,8 @@ a mid(filler1, 1,10) length(filler1)=length(filler2)
16 filler1234 1
17 filler1234 1
18 filler1234 1
-19 filler1234 1
3 duplicate 1
+19 filler1234 1
19 duplicate 1
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
@@ -317,7 +307,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -358,7 +348,7 @@ WHERE Language='English' AND Percentage > 10 AND
t2.Population > 100000);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 range Population,Country Population 4 NULL 1 Using index condition; Rowid-ordered scan; Start temporary
-1 PRIMARY t2 eq_ref PRIMARY,Population PRIMARY 3 test.t1.Country 1 Using where; End temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t2 eq_ref|filter PRIMARY,Population PRIMARY|Population 3|4 test.t1.Country 1 (75%) Using where; End temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
1 PRIMARY t3 eq_ref PRIMARY,Percentage PRIMARY 33 test.t1.Country,const 1 Using index condition; Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
set optimizer_switch=@bug35674_save_optimizer_switch;
DROP TABLE t1,t2,t3;
@@ -852,10 +842,10 @@ explain
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index
-1 PRIMARY alias2 index f12 f12 7 NULL # Using index; Start temporary
-1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join)
-1 PRIMARY t3 hash_ALL NULL #hash#$hj 3 test.alias2.f12 # Using where; End temporary; Using join buffer (incremental, BNLH join)
+1 PRIMARY alias1 const PRIMARY PRIMARY 4 const #
+1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan
+1 PRIMARY t1 ALL NULL NULL NULL NULL # FirstMatch(alias2)
+1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
f12
@@ -923,10 +913,11 @@ EXPLAIN
SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
WHERE t3.b IN (SELECT b FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 ALL NULL NULL NULL NULL 1 Using where
+1 PRIMARY t3 ALL NULL NULL NULL NULL 1
1 PRIMARY t2 hash_ALL NULL #hash#$hj 4 test.t3.a 1 Using where; Using join buffer (flat, BNLH join)
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join)
-1 PRIMARY t4 hash_ALL NULL #hash#$hj 4 test.t3.b 2 Using where; Start temporary; End temporary; Using join buffer (incremental, BNLH join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 2
3 DERIVED t1 ALL NULL NULL NULL NULL 1
SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
WHERE t3.b IN (SELECT b FROM t4);
@@ -1246,10 +1237,10 @@ t1_pk1 t1_pk2 t3_i t3_c
explain
SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' );
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
-1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY t4 hash_index NULL #hash#$hj:PRIMARY 54:59 test.t2.t2_c 2 Using where; Using index; Using join buffer (incremental, BNLH join)
-1 PRIMARY t3 hash_ALL NULL #hash#$hj 38 test.t2.t2_c 2 Using where; End temporary; Using join buffer (incremental, BNLH join)
+1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t3); Using join buffer (incremental, BNL join)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
@@ -1367,9 +1358,9 @@ WHERE
T3_0_.t3idref= 1
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary
+1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Start temporary
1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1 Using join buffer (flat, BKA join); Key-ordered scan
-1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index
+1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using join buffer (incremental, BKA join); Key-ordered scan
1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary
drop table t3,t2,t1;
set optimizer_search_depth=@tmp7474;
@@ -1469,17 +1460,18 @@ CREATE TABLE t3 (pk int PRIMARY KEY, a int);
INSERT INTO t3 VALUES (1, 6), (2, 8);
CREATE TABLE t4 (b int) ENGINE=InnoDB;
INSERT INTO t4 VALUES (2),(88),(99);
+insert into t2 select seq from seq_100_to_200;
set @tmp_optimizer_switch=@@optimizer_switch;
SET optimizer_switch = 'semijoin_with_cache=on';
SET join_cache_level = 2;
EXPLAIN
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 1
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3
-2 MATERIALIZED t3 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL #
+1 PRIMARY t2 ALL NULL NULL NULL NULL # Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL # Using where
+2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t4.b #
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
pk a b
1 6 8
diff --git a/mysql-test/main/subselect_sj2_jcl6.test b/mysql-test/main/subselect_sj2_jcl6.test
index ea3f07b289a..1001a213768 100644
--- a/mysql-test/main/subselect_sj2_jcl6.test
+++ b/mysql-test/main/subselect_sj2_jcl6.test
@@ -68,11 +68,14 @@ INSERT INTO t3 VALUES (1, 6), (2, 8);
CREATE TABLE t4 (b int) ENGINE=InnoDB;
INSERT INTO t4 VALUES (2),(88),(99);
+insert into t2 select seq from seq_100_to_200;
+
set @tmp_optimizer_switch=@@optimizer_switch;
SET optimizer_switch = 'semijoin_with_cache=on';
SET join_cache_level = 2;
+--replace_column 9 #
EXPLAIN
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
diff --git a/mysql-test/main/subselect_sj2_mat.result b/mysql-test/main/subselect_sj2_mat.result
index e05cb85b470..a04e6333b07 100644
--- a/mysql-test/main/subselect_sj2_mat.result
+++ b/mysql-test/main/subselect_sj2_mat.result
@@ -27,11 +27,7 @@ key(b)
);
insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
-select * from t1;
-a b
-1 1
-1 1
-2 2
+insert into t1 values (1030,30),(1031,31),(1032,32),(1033,33);
select * from t2;
a b
0 0
@@ -56,9 +52,9 @@ a b
19 14
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t2 ref b b 5 test.t1.a 2
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t2 ALL b NULL NULL NULL 20
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 7
select * from t2 where b in (select a from t1);
a b
1 1
@@ -84,9 +80,9 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t3 ref b b 5 test.t1.a 2
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t3 ALL b NULL NULL NULL 20
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 7
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -114,9 +110,8 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL #
-1 PRIMARY t3 ref b b 5 test.t0.a #
-2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t0 ALL NULL NULL NULL NULL # Using where; Start temporary
+1 PRIMARY t3 ref b b 5 test.t0.a # End temporary
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
a b pk1 pk2
0 0 0 0
@@ -137,19 +132,17 @@ set join_buffer_size= @save_join_buffer_size;
set max_heap_table_size= @save_max_heap_table_size;
explain select * from t1 where a in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where
1 PRIMARY t2 ref b b 5 test.t1.a 1 Using index; FirstMatch(t1)
-select * from t1;
-a b
-1 1
-1 1
-2 2
select * from t1 where a in (select b from t2);
a b
1 1
1 1
2 2
drop table t1, t2, t3;
+#
+# Test join buffering
+#
set @save_join_buffer_size = @@join_buffer_size;
set join_buffer_size= 8192;
create table t1 (a int, filler1 binary(200), filler2 binary(200));
@@ -309,7 +302,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -350,7 +343,7 @@ WHERE Language='English' AND Percentage > 10 AND
t2.Population > 100000);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 range Population,Country Population 4 NULL 1 Using index condition; Rowid-ordered scan; Start temporary
-1 PRIMARY t2 eq_ref PRIMARY,Population PRIMARY 3 test.t1.Country 1 Using where; End temporary
+1 PRIMARY t2 eq_ref|filter PRIMARY,Population PRIMARY|Population 3|4 test.t1.Country 1 (75%) Using where; End temporary; Using rowid filter
1 PRIMARY t3 eq_ref PRIMARY,Percentage PRIMARY 33 test.t1.Country,const 1 Using index condition; Using where
set optimizer_switch=@bug35674_save_optimizer_switch;
DROP TABLE t1,t2,t3;
@@ -842,9 +835,9 @@ explain
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index
+1 PRIMARY alias1 const PRIMARY PRIMARY 4 const #
1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan
-1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2)
+1 PRIMARY t1 ALL NULL NULL NULL NULL # FirstMatch(alias2)
1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
@@ -1237,10 +1230,10 @@ t1_pk1 t1_pk2 t3_i t3_c
explain
SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' );
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
+1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
-1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t3)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
@@ -1358,9 +1351,9 @@ WHERE
T3_0_.t3idref= 1
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary
+1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Start temporary
1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1
-1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index
+1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1
1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary
drop table t3,t2,t1;
set optimizer_search_depth=@tmp7474;
@@ -1566,7 +1559,7 @@ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary
1 PRIMARY t1 ref idx idx 2 test.t4.a4 1 100.00 Using index
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 16.67 End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t4`) left join `test`.`t2` on(`test`.`t2`.`a2` = `test`.`t4`.`a4`) where `test`.`t4`.`b4` = `test`.`t4`.`a4` and `test`.`t1`.`b1` = `test`.`t4`.`a4`
@@ -1584,7 +1577,7 @@ WHERE ( b1, b1 ) IN ( SELECT a4, b4 FROM t3, t4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary
1 PRIMARY t1 ref idx idx 2 test.t4.a4 1 100.00 Using index
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 16.67 End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t4`) left join `test`.`t2` on(`test`.`t2`.`a2` = `test`.`t4`.`a4`) where `test`.`t4`.`b4` = `test`.`t4`.`a4` and `test`.`t1`.`b1` = `test`.`t4`.`a4`
@@ -1619,7 +1612,7 @@ WHERE c1 IN ( SELECT c4 FROM t3,t4 WHERE c3 = c4);
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 t4 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY t3 ALL NULL NULL NULL NULL 10 100.00 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 10 5.00 Using where; End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t4`) left join `test`.`t2` on(`test`.`t2`.`c2` = `test`.`t1`.`c1` or `test`.`t1`.`c1` > 'z') where `test`.`t4`.`c4` = `test`.`t1`.`c1` and `test`.`t3`.`c3` = `test`.`t1`.`c1`
@@ -1678,12 +1671,12 @@ set optimizer_switch='materialization=on,semijoin=on';
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 100.00
-1 PRIMARY t1 hash_ALL NULL #hash#$hj 5 test.t2.i2 5 100.00 Using where; Using join buffer (flat, BNLH join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Using where
2 MATERIALIZED t3 hash_ALL NULL #hash#$hj 5 test.t2.i2 3 100.00 Using where; Using join buffer (flat, BNLH join)
Warnings:
-Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`i1` = `test`.`t2`.`i2`
+Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where `test`.`t3`.`i3` = `test`.`t2`.`i2`
SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 = i2 OR 1=2);
i1
7
@@ -1691,12 +1684,12 @@ EXPLAIN EXTENDED
SELECT * FROM t1
WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 0 AND i3 = i2 OR 1=2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 100.00
-1 PRIMARY t1 hash_ALL NULL #hash#$hj 5 test.t2.i2 5 100.00 Using where; Using join buffer (flat, BNLH join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Using where
2 MATERIALIZED t3 hash_ALL NULL #hash#$hj 5 test.t2.i2 3 100.00 Using where; Using join buffer (flat, BNLH join)
Warnings:
-Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`i1` = `test`.`t2`.`i2` and `test`.`t3`.`i3` > 0
+Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t3`.`i3` > 0
SELECT * FROM t1
WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 0 AND i3 = i2 OR 1=2);
i1
@@ -1723,11 +1716,10 @@ i
explain extended
select * from t1 where (rand() < 0) and i in (select i from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 10 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 10 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where rand() < 0
+Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`i` = `test`.`t1`.`i` and rand() < 0
drop table t1,t2;
set optimizer_switch=@save_optimizer_switch;
#
@@ -1754,7 +1746,7 @@ WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' )
HAVING f1 != 'foo'
ORDER BY f1;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 index f1 f1 11 NULL 2 Using where; Using index; Using temporary; Using filesort
+1 PRIMARY t1 range f1 f1 11 NULL 2 Using where; Using index; Using temporary; Using filesort
1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
#
@@ -1793,7 +1785,7 @@ OR
(t.id IN (0,4,12,13,1,10,3,11))
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t index PRIMARY PRIMARY 4 NULL 114 Using where; Using index
+1 PRIMARY t ALL PRIMARY NULL NULL NULL 114 Using where
2 MATERIALIZED A ALL PRIMARY NULL NULL NULL 114
2 MATERIALIZED <subquery3> eq_ref distinct_key distinct_key 67 func 1
3 MATERIALIZED B range PRIMARY PRIMARY 4 NULL 8 Using where
@@ -1957,20 +1949,16 @@ AND t3.id_product IN (SELECT id_product FROM t2 t2_3 WHERE t2_3.id_t2 = 18 OR t2
AND t3.id_product IN (SELECT id_product FROM t2 t2_4 WHERE t2_4.id_t2 = 34 OR t2_4.id_t2 = 23)
AND t3.id_product IN (SELECT id_product FROM t2 t2_5 WHERE t2_5.id_t2 = 29 OR t2_5.id_t2 = 28 OR t2_5.id_t2 = 26);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using index
-1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.id_product 1 Using index
-1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t1.id_product,const 1 Using where; Using index
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY <subquery6> eq_ref distinct_key distinct_key 4 func 1 Using where
+1 PRIMARY t2_2 ref id_t2,id_product id_t2 5 const 12 Using where; Start temporary
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t2_2.id_product 1 Using where; Using index; End temporary
+1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t3.id_product,const 1 Using where; Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 Using where
+1 PRIMARY t2_3 range id_t2,id_product id_t2 5 NULL 33 Using index condition; Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_4 range id_t2,id_product id_t2 5 NULL 18 Using index condition; Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_5 range id_t2,id_product id_t2 5 NULL 31 Using index condition; Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t5 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
-3 MATERIALIZED t2_2 ref id_t2,id_product id_t2 5 const 12
-4 MATERIALIZED t2_3 range id_t2,id_product id_t2 5 NULL 33 Using index condition; Using where
-5 MATERIALIZED t2_4 range id_t2,id_product id_t2 5 NULL 18 Using index condition; Using where
-6 MATERIALIZED t2_5 range id_t2,id_product id_t2 5 NULL 31 Using index condition; Using where
-2 MATERIALIZED t2_1 ref id_t2,id_product id_t2 5 const 51
+1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t2_1 ALL id_t2,id_product NULL NULL NULL 223 Using where
set optimizer_switch='rowid_filter=default';
drop table t1,t2,t3,t4,t5;
set global innodb_stats_persistent= @innodb_stats_persistent_save;
diff --git a/mysql-test/main/subselect_sj_jcl6.result b/mysql-test/main/subselect_sj_jcl6.result
index d07002f978e..78b2518891f 100644
--- a/mysql-test/main/subselect_sj_jcl6.result
+++ b/mysql-test/main/subselect_sj_jcl6.result
@@ -87,19 +87,19 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t12` join `test`.`t1` where `test`.`t12`.`pk` = `test`.`t10`.`a` and `test`.`t10`.`pk` = `test`.`t1`.`a`
subqueries within outer joins go into ON expr.
-explAin extended
+explain extended
select * from t1 left join (t2 A, t2 B) on ( A.A= t1.A And B.A in (select pk from t10));
-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 A ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer (flAt, BNL join)
1 PRIMARY B ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer (incrementAl, BNL join)
-2 MATERIALIZED t10 index PRIMARY PRIMARY 4 NULL 10 100.00 Using index
+2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(`test`.`A`.`A` = `test`.`t1`.`A` And <in_optimizer>(`test`.`B`.`A`,`test`.`B`.`A` in ( <mAteriAlize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` ), <primAry_index_lookup>(`test`.`B`.`A` in <temporAry tABle> on distinct_key where `test`.`B`.`A` = `<suBquery2>`.`pk`)))) where 1
+Note 1003 /* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(`test`.`A`.`A` = `test`.`t1`.`A` And <in_optimizer>(`test`.`B`.`A`,<exists>(<primAry_index_lookup>(<cAche>(`test`.`B`.`A`) in t10 on PRIMARY)))) where 1
t2 should be wrapped into OJ-nest, so we have "t1 LJ (t2 J t10)"
-explAin extended
+explain extended
select * from t1 left join t2 on (t2.A= t1.A And t2.A in (select pk from t10));
-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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer (flAt, BNL join)
2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
@@ -355,8 +355,8 @@ WHERE PNUM IN
(SELECT PNUM FROM PROJ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY STAFF ALL NULL NULL NULL NULL 5
-1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
-1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF); Using join buffer (incremental, BNL join)
+1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@@ -513,7 +513,7 @@ EXPLAIN EXTENDED SELECT vkey FROM t0 WHERE pk IN
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t0 ALL PRIMARY NULL NULL NULL 5 100.00
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t0.pk 1 100.00 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY t2 ref vkey vkey 4 test.t1.vnokey 2 100.00 Using index; FirstMatch(t1)
+1 PRIMARY t2 ref vkey vkey 4 test.t1.vnokey 2 50.00 Using index; FirstMatch(t1)
Warnings:
Note 1003 select `test`.`t0`.`vkey` AS `vkey` from `test`.`t0` `t1` semi join (`test`.`t0` `t2`) join `test`.`t0` where `test`.`t1`.`pk` = `test`.`t0`.`pk` and `test`.`t2`.`vkey` = `test`.`t1`.`vnokey`
SELECT vkey FROM t0 WHERE pk IN
@@ -817,10 +817,9 @@ insert into t2 (pk) values (-1),(0);
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
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 <subquery2> eq_ref distinct_key distinct_key 11 func,func 1 100.00
-2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan
+1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`pk` > 0
+Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t2`.`b` = `test`.`t1`.`b` and `test`.`t2`.`pk` > 0
SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
pk
2
@@ -986,10 +985,9 @@ FROM t1
WHERE `varchar_nokey` < 'n' XOR `pk` ) ;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 18 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
-2 MATERIALIZED t1 ALL varchar_key NULL NULL NULL 15 100.00 Using where
+1 PRIMARY t1 ref varchar_key varchar_key 3 test.t2.varchar_nokey 2 100.00 Using where; FirstMatch(t2); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
Warnings:
-Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`varchar_nokey` = `test`.`t1`.`varchar_key` and (`test`.`t1`.`varchar_key` < 'n' xor `test`.`t1`.`pk`)
+Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where `test`.`t1`.`varchar_key` = `test`.`t2`.`varchar_nokey` and `test`.`t1`.`varchar_nokey` = `test`.`t2`.`varchar_nokey` and (`test`.`t2`.`varchar_nokey` < 'n' xor `test`.`t1`.`pk`)
SELECT varchar_nokey
FROM t2
WHERE ( `varchar_nokey` , `varchar_nokey` ) IN (
@@ -1068,10 +1066,8 @@ AND t1.val IN (SELECT t3.val FROM t3
WHERE t3.val LIKE 'a%' OR t3.val LIKE 'e%');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 13 func 1
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 13 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 Using where
-3 MATERIALIZED t3 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 6 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where; FirstMatch(t2); Using join buffer (incremental, BNL join)
SELECT *
FROM t1
WHERE t1.val IN (SELECT t2.val FROM t2
@@ -1653,11 +1649,9 @@ select * from t1 A, t1 B
where A.a = B.a and A.a in (select a from t2 C) and B.a in (select a from t2 D);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 5
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-1 PRIMARY B ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED C ALL NULL NULL NULL NULL 5
-3 MATERIALIZED D ALL NULL NULL NULL NULL 5
+1 PRIMARY C ALL NULL NULL NULL NULL 5 Using where; FirstMatch(A); Using join buffer (flat, BNL join)
+1 PRIMARY B ALL NULL NULL NULL NULL 5 Using where; Using join buffer (incremental, BNL join)
+1 PRIMARY D ALL NULL NULL NULL NULL 5 Using where; FirstMatch(B); Using join buffer (incremental, BNL join)
drop table t1, t2;
#
# BUG#784441: Abort on semijoin with a view as the inner table
@@ -2010,7 +2004,7 @@ explain extended
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
-1 PRIMARY t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index; FirstMatch(t2)
+1 PRIMARY t4 ref_or_null f2 f2 5 const 4 25.00 Using where; Using index; FirstMatch(t2)
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
@@ -2166,8 +2160,8 @@ explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
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 t3 ref b b 5 test.t1.b 2 Start temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ref b b 5 test.t1.b 2 Using where; Start temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using index; End temporary
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
5 6
@@ -2190,10 +2184,10 @@ INSERT INTO t5 VALUES (7,0),(9,0);
explain
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; LooseScan
-1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where
-1 PRIMARY t4 ALL NULL NULL NULL NULL 3 FirstMatch(t5)
-1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; Start temporary
+1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
a
0
@@ -2272,10 +2266,10 @@ alias1.c IN (SELECT SQ3_alias1.b
FROM t2 AS SQ3_alias1 STRAIGHT_JOIN t2 AS SQ3_alias2)
LIMIT 100;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20
-1 PRIMARY alias2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
-1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (incremental, BNL join)
-1 PRIMARY SQ3_alias1 ALL NULL NULL NULL NULL 20 Using where; Start temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY alias2 ALL NULL NULL NULL NULL 20
+1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
+1 PRIMARY SQ3_alias1 ALL NULL NULL NULL NULL 20 Start temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY SQ3_alias2 index NULL PRIMARY 4 NULL 20 Using index; End temporary; Using join buffer (incremental, BNL join)
2 DERIVED t2 ALL NULL NULL NULL NULL 20
create table t3 as
@@ -2448,9 +2442,9 @@ SET SESSION optimizer_switch='loosescan=off';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index idx idx 9 NULL 2 Using where; Using index; Start temporary
-1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY t2 range idx idx 4 NULL 2 Using where; Using index
+1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
a
5
@@ -2458,9 +2452,9 @@ SET SESSION optimizer_switch='loosescan=on';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index idx idx 9 NULL 2 Using where; Using index; Start temporary
-1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY t2 range idx idx 4 NULL 2 Using where; Using index
+1 PRIMARY t3 ref idx idx 4 test.t2.b 1 Using index; FirstMatch(t1)
SELECT * FROM t1 WHERE a IN (SELECT t2.a FROM t2,t3 WHERE t2.b = t3.b);
a
5
@@ -2587,7 +2581,7 @@ WHERE ( b, d ) IN
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary
1 PRIMARY t2 ref c c 5 test.t1.b 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY t1 ref b b 5 test.t1.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t1 ALL b NULL NULL NULL 10 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
@@ -2779,8 +2773,8 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where
-1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary
-1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary
+1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11
+1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2)
3 DERIVED t1 ALL NULL NULL NULL NULL 11
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
@@ -3048,7 +3042,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5 100.00 Start temporary
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 10.00 Using where; End temporary; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1`,'x' AS `c2` from `test`.`t1` semi join (`test`.`t1` left join `test`.`t3` on(`test`.`t1`.`c1` = `test`.`t3`.`c3`)) where `test`.`t1`.`pk` = `test`.`t1`.`pk` order by 'x',`test`.`t1`.`c1`
DROP TABLE t1,t2,t3;
@@ -3300,7 +3294,7 @@ explain extended
SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00
-1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ref col1 col1 5 const 2 50.00 Using index condition; Using where; FirstMatch(t1)
Warnings:
Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null
DROP TABLE t1, t2;
@@ -3481,20 +3475,21 @@ INSERT INTO t2 VALUES ('v'), ('v'), ('s'), ('j');
CREATE TABLE t3 (c varchar(1), d varchar(1), INDEX idx_c(c) );
INSERT INTO t3 VALUES ('v','v'), ('v','v'), ('s','s'), ('j','j');
INSERT INTO t3 VALUES ('m','m'), ('d','d'), ('k','k'), ('m','m');
+insert into t1 select 'z','z' from seq_1_to_20;
set @tmp_otimizer_switch= @@optimizer_switch;
set @tmp_join_cache_level=@@join_cache_level;
set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on';
set join_cache_level=0;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL idx_a NULL NULL NULL 3
+1 PRIMARY t1 ALL idx_a NULL NULL NULL 23
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
1 PRIMARY t2 ref idx_c idx_c 4 test.t1.b 2 Using where; Using index
-2 MATERIALIZED t ALL idx_a NULL NULL NULL 3
+2 MATERIALIZED t ALL idx_a NULL NULL NULL 23
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
a b c
v v v
v v v
@@ -3502,14 +3497,13 @@ w w NULL
t t NULL
EXPLAIN
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL idx_a NULL NULL NULL 3
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-1 PRIMARY t3 ref idx_c idx_c 4 test.t1.b 2 Using where
-2 MATERIALIZED t ALL idx_a NULL NULL NULL 3
+1 PRIMARY t ALL idx_a NULL NULL NULL 23 Using where; Start temporary
+1 PRIMARY t1 ref idx_a idx_a 4 test.t.a 2 Using where; End temporary
+1 PRIMARY t3 ref idx_c idx_c 4 test.t.b 2 Using where
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
a b c d
v v v v
v v v v
@@ -3518,14 +3512,14 @@ t t NULL NULL
set join_cache_level=6;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL idx_a NULL NULL NULL 3
+1 PRIMARY t1 ALL idx_a NULL NULL NULL 23
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
1 PRIMARY t2 ref idx_c idx_c 4 test.t1.b 2 Using where; Using index
-2 MATERIALIZED t ALL idx_a NULL NULL NULL 3
+2 MATERIALIZED t ALL idx_a NULL NULL NULL 23
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
a b c
v v v
v v v
@@ -3533,14 +3527,13 @@ w w NULL
t t NULL
EXPLAIN
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL idx_a NULL NULL NULL 3
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-1 PRIMARY t3 ref idx_c idx_c 4 test.t1.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-2 MATERIALIZED t ALL idx_a NULL NULL NULL 3
+1 PRIMARY t ALL idx_a NULL NULL NULL 23 Start temporary
+1 PRIMARY t1 ALL idx_a NULL NULL NULL 23 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ref idx_c idx_c 4 test.t.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
-WHERE (a, b) IN (SELECT a, b FROM t1 t);
+WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
a b c d
v v v v
v v v v
diff --git a/mysql-test/main/subselect_sj_jcl6.test b/mysql-test/main/subselect_sj_jcl6.test
index f4f605c0406..e39a6887bde 100644
--- a/mysql-test/main/subselect_sj_jcl6.test
+++ b/mysql-test/main/subselect_sj_jcl6.test
@@ -3,6 +3,7 @@
#
--source include/no_valgrind_without_big.inc
--source include/default_optimizer_switch.inc
+--source include/have_sequence.inc
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='optimize_join_buffer_size=on';
@@ -132,6 +133,8 @@ CREATE TABLE t3 (c varchar(1), d varchar(1), INDEX idx_c(c) );
INSERT INTO t3 VALUES ('v','v'), ('v','v'), ('s','s'), ('j','j');
INSERT INTO t3 VALUES ('m','m'), ('d','d'), ('k','k'), ('m','m');
+insert into t1 select 'z','z' from seq_1_to_20;
+
set @tmp_otimizer_switch= @@optimizer_switch;
set @tmp_join_cache_level=@@join_cache_level;
set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on';
@@ -140,29 +143,29 @@ set join_cache_level=0;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
EXPLAIN
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
set join_cache_level=6;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
SELECT * FROM t1 LEFT JOIN t2 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
EXPLAIN
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
SELECT * FROM t1 LEFT JOIN t3 ON (c = b)
- WHERE (a, b) IN (SELECT a, b FROM t1 t);
+ WHERE (a, b) IN (SELECT a, b FROM t1 t) having t1.a !='z';
set optimizer_switch=@tmp_optimizer_switch;
set join_cache_level=@tmp_join_cache_level;
diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result
index 876b292df2d..68af9e9cd35 100644
--- a/mysql-test/main/subselect_sj_mat.result
+++ b/mysql-test/main/subselect_sj_mat.result
@@ -108,7 +108,7 @@ explain extended
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2i index it2i1,it2i3 it2i1 # NULL 5 50.00 Using where; Using index; LooseScan
-1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00
+1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 20.00
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` > '0'
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
@@ -118,11 +118,11 @@ a1 a2
explain extended
select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i index it1i1,it1i3 # 18 # 3 100.00 #
-1 PRIMARY <subquery2> eq_ref distinct_key # 8 # 1 100.00 #
+1 PRIMARY <subquery2> ALL distinct_key # NULL # 5 100.00 #
+1 PRIMARY t1i ref it1i1,it1i3 # 9 # 1 100.00 #
2 MATERIALIZED t2i range it2i1,it2i3 # 9 # 5 100.00 #
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select max(`test`.`t2i`.`b1`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`max(b1)` = `test`.`t1i`.`a1`
+Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select max(`test`.`t2i`.`b1`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `test`.`t1i`.`a1` = `<subquery2>`.`max(b1)`
select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1);
a1 a2
1 - 01 2 - 01
@@ -131,7 +131,7 @@ explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 50.00 Using where; Using index; LooseScan
-1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00
+1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 20.00
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0'
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
@@ -141,11 +141,11 @@ a1 a2
explain extended
select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i index it1i1,it1i2,it1i3 # # # 3 100.00 #
-1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 #
+1 PRIMARY <subquery2> ALL distinct_key # # # 5 100.00 #
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
2 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`max(b2)` = `test`.`t1i`.`a2`
+Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`max(b2)`
select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1);
a1 a2
1 - 01 2 - 01
@@ -153,11 +153,11 @@ a1 a2
explain extended
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i index it1i1,it1i2,it1i3 # # # 3 100.00 #
-1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 #
+1 PRIMARY <subquery2> ALL distinct_key # # # 5 100.00 #
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
2 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`min(b2)` = `test`.`t1i`.`a2`
+Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`min(b2)`
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
a1 a2
1 - 01 2 - 01
@@ -277,7 +277,7 @@ explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 50.00 Using where; Using index; LooseScan
-1 PRIMARY t1i ref it1i1,it1i2,it1i3 it1i3 18 test.t2i.b1,test.t2i.b2 1 100.00 Using index
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 it1i3 18 test.t2i.b1,test.t2i.b2 1 20.00 Using index
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2`
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
@@ -329,14 +329,12 @@ where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
(a1, a2) in (select c1, c2 from t3
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
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 <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 16 func,func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where
-3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where
-3 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+1 PRIMARY t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t1.a1,test.t1.a2 1 100.00 Using index; Start temporary
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 4 15.00 Using where; End temporary; Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and `test`.`t2`.`b1` > '0' and `test`.`t3`.`c2` > '0'
+Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t1`.`a1` and `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t1`.`a2` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and `test`.`t3`.`c2` = `test`.`t1`.`a2` and `test`.`t1`.`a1` > '0' and `test`.`t1`.`a2` > '0'
select * from t1
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
(a1, a2) in (select c1, c2 from t3
@@ -351,9 +349,9 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
-1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 20.00 #
1 PRIMARY t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
-1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 1 60.00 #
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0'
select * from t1i
@@ -371,16 +369,14 @@ b2 in (select c2 from t3 where c2 LIKE '%03')) and
(a1, a2) in (select c1, c2 from t3
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
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 <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00
-1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where
-5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where
-5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3.c1,test.t3.c2 1 100.00 Using index
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+1 PRIMARY t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t1.a1,test.t1.a2 1 100.00 Using index; Start temporary
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 4 15.00 Using where; End temporary; Using join buffer (flat, BNL join)
4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0'
+Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t1`.`a1` and `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t1`.`a2` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and `test`.`t3`.`c2` = `test`.`t1`.`a2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t1`.`a2` > '0'
select * from t1
where (a1, a2) in (select b1, b2 from t2
where b2 in (select c2 from t3 where c2 LIKE '%02') or
@@ -398,7 +394,7 @@ b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00
5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 100.00 Using where
5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3c.c1,test.t3c.c2 1 100.00 Using index
@@ -431,20 +427,18 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL # # # 3 100.00 #
-1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 #
-1 PRIMARY <subquery5> eq_ref distinct_key # # # 1 100.00 #
-2 MATERIALIZED t2 ALL NULL # # # 5 100.00 #
-5 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
-5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+1 PRIMARY t2 ALL NULL # # # 5 20.00 #
+1 PRIMARY t3 ALL NULL # # # 4 15.00 #
4 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
3 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
-7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
+7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 20.00 #
7 UNION t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
-7 UNION t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+7 UNION t2i ref it2i1,it2i2,it2i3 # # # 1 60.00 #
NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
Warnings:
-Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0')
+Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t1`.`a1` and `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t1`.`a2` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and `test`.`t3`.`c2` = `test`.`t1`.`a2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t1`.`a2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0')
(select * from t1
where (a1, a2) in (select b1, b2 from t2
where b2 in (select c2 from t3 where c2 LIKE '%02') or
@@ -536,9 +530,9 @@ b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t1.a1,test.t1.a2 1 100.00 Using index; Start temporary
-1 PRIMARY t3c ALL NULL NULL NULL NULL 4 100.00 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3c ALL NULL NULL NULL NULL 4 15.00 Using where; End temporary; Using join buffer (flat, BNL join)
4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where
3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
@@ -652,7 +646,7 @@ from t1_16
where a1 in (select b1 from t2_16 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` semi join (`test`.`t2_16`) where `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t1_16`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -666,7 +660,7 @@ from t1_16
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` semi join (`test`.`t2_16`) where `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t2_16`.`b2` = `test`.`t1_16`.`a2` and `test`.`t1_16`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -733,7 +727,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 0.56 Using where; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t2_16` join `test`.`t2` join `test`.`t1_16`) where `test`.`t2`.`b1` = `test`.`t3`.`c1` and `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t2_16`.`b2` = `test`.`t1_16`.`a2` and `test`.`t2`.`b2` = substr(`test`.`t1_16`.`a2`,1,6) and `test`.`t3`.`c2` > '0' and concat(`test`.`t1`.`a1`,'x') = left(`test`.`t1_16`.`a1`,8)
drop table t1_16, t2_16, t3_16;
@@ -767,7 +761,7 @@ from t1_512
where a1 in (select b1 from t2_512 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` semi join (`test`.`t2_512`) where `test`.`t2_512`.`b1` = `test`.`t1_512`.`a1` and `test`.`t1_512`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -781,7 +775,7 @@ from t1_512
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` semi join (`test`.`t2_512`) where `test`.`t2_512`.`b1` = `test`.`t1_512`.`a1` and `test`.`t2_512`.`b2` = `test`.`t1_512`.`a2` and `test`.`t1_512`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -871,7 +865,7 @@ from t1_1024
where a1 in (select b1 from t2_1024 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` = `test`.`t1_1024`.`a1` and `test`.`t1_1024`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -885,7 +879,7 @@ from t1_1024
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` = `test`.`t1_1024`.`a1` and `test`.`t2_1024`.`b2` = `test`.`t1_1024`.`a2` and `test`.`t1_1024`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -899,7 +893,7 @@ from t1_1024
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` > '0' and `test`.`t1_1024`.`a1` = substr(`test`.`t2_1024`.`b1`,1,1024)
select left(a1,7), left(a2,7)
@@ -974,7 +968,7 @@ from t1_1025
where a1 in (select b1 from t2_1025 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` = `test`.`t1_1025`.`a1` and `test`.`t1_1025`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -988,7 +982,7 @@ from t1_1025
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` = `test`.`t1_1025`.`a1` and `test`.`t2_1025`.`b2` = `test`.`t1_1025`.`a2` and `test`.`t1_1025`.`a1` > '0'
select left(a1,7), left(a2,7)
@@ -1002,7 +996,7 @@ from t1_1025
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` > '0' and `test`.`t1_1025`.`a1` = substr(`test`.`t2_1025`.`b1`,1,1025)
select left(a1,7), left(a2,7)
@@ -1084,7 +1078,7 @@ from t1bb
where (a1, a2) in (select b1, b2 from t2bb);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2bb ALL NULL NULL NULL NULL 3 33.33 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` semi join (`test`.`t2bb`) where `test`.`t2bb`.`b1` = `test`.`t1bb`.`a1` and `test`.`t2bb`.`b2` = `test`.`t1bb`.`a2`
select bin(a1), a2
@@ -1146,11 +1140,10 @@ create index it1a on t1(a);
explain extended
select a from t1 where a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index it1a it1a 4 NULL 7 100.00 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where; Start temporary
+1 PRIMARY t1 ref it1a it1a 4 test.t2.c 2 16.67 Using index; End temporary
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`d` >= 20
+Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and `test`.`t2`.`d` >= 20
select a from t1 where a in (select c from t2 where d >= 20);
a
2
@@ -1161,11 +1154,10 @@ insert into t2 values (1,10);
explain extended
select a from t1 where a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index it1a it1a 4 NULL 7 100.00 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 Using where; Start temporary
+1 PRIMARY t1 ref it1a it1a 4 test.t2.c 2 14.29 Using index; End temporary
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`d` >= 20
+Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and `test`.`t2`.`d` >= 20
select a from t1 where a in (select c from t2 where d >= 20);
a
2
@@ -1175,7 +1167,7 @@ a
explain extended
select a from t1 group by a having a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL it1a 4 NULL 7 100.00 Using index for group-by
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`))))
@@ -1187,7 +1179,7 @@ create index iab on t1(a, b);
explain extended
select a from t1 group by a having a in (select c from t2 where d >= 20);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL it1a 4 NULL 7 100.00 Using index for group-by
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`))))
@@ -1199,7 +1191,7 @@ explain extended
select a from t1 group by a
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index
+1 PRIMARY t1 range NULL iab 4 NULL 7 100.00 Using index for group-by
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
@@ -1216,7 +1208,7 @@ select a from t1
where a in (select c from t2 where d >= some(select e from t3 where b=e));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 Start temporary
-1 PRIMARY t1 ref it1a,iab iab 4 test.t2.c 1 100.00 Using where; Using index; End temporary
+1 PRIMARY t1 ref it1a,iab iab 4 test.t2.c 1 14.29 Using where; Using index; End temporary
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
@@ -1549,6 +1541,9 @@ COUNT(*)
2
set @@optimizer_switch= @local_optimizer_switch;
DROP TABLE t1, t2;
+#
+# BUG#46548 IN-subqueries return 0 rows with materialization=on
+#
CREATE TABLE t1 (
pk int,
a varchar(1),
@@ -1558,15 +1553,19 @@ d varchar(4),
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
+insert into t1 select seq,'x','xxxx','xxxx','xxxx' from seq_10_to_40;
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
+insert into t2 select -seq,'a','aaaa','aaaa','aaaa' from seq_1_to_20;
+insert into t2 select seq,'b','bbbb','bbbb','bbbb' from seq_100_to_200;
set @local_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 33
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL PRIMARY NULL NULL NULL 123 Using where
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
pk
2
@@ -1885,7 +1884,7 @@ SELECT * FROM t1
WHERE a IN ( SELECT MIN(a) FROM t1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system a NULL NULL NULL 1 100.00
-1 PRIMARY <subquery2> system NULL NULL NULL NULL 1 100.00
+1 PRIMARY <subquery2> system NULL NULL NULL NULL 0 0.00
2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Note 1003 /* select#1 */ select 8 AS `a` from dual where 1
@@ -1927,12 +1926,13 @@ DROP TABLE t1,t2;
#
create table t1 (a int, b int);
insert into t1 values (7,5), (3,3), (5,4), (9,3);
+insert into t1 select seq,seq from seq_100_to_200;
create table t2 (a int, b int, index i_a(a));
insert into t2 values
(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1);
explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
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 105
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where
select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
@@ -2228,8 +2228,8 @@ mysqltest1
EXPLAIN EXTENDED
SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY schemata ALL NULL NULL NULL NULL NULL NULL Start temporary; Using temporary; Using filesort
-1 PRIMARY t1 eq_ref db db 764 information_schema.schemata.SCHEMA_NAME 1 100.00 Using where; Using index; End temporary
+1 PRIMARY t1 index db db 764 NULL 4 100.00 Using index; Using temporary; Using filesort
+1 PRIMARY schemata ALL NULL NULL NULL NULL NULL NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`db` AS `db` from `test`.`t1` semi join (`information_schema`.`schemata`) where `test`.`t1`.`db` = `information_schema`.`schemata`.`SCHEMA_NAME` order by `test`.`t1`.`db` desc
drop table t1;
@@ -2261,8 +2261,10 @@ drop table t1;
CREATE TABLE t1 (
pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
+create table t2 like t1;
+insert into t2 select * from t1;
SELECT sq1.f2 FROM t1 AS sq1
-WHERE EXISTS ( SELECT * FROM t1 AS sq2
+WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
@@ -2279,12 +2281,12 @@ id select_type table type possible_keys key key_len ref rows Extra
# this checks the result set above
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
-WHERE EXISTS ( SELECT * FROM t1 AS sq2
+WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
set optimizer_switch= @local_optimizer_switch;
-DROP TABLE t1;
+DROP TABLE t1,t2;
#
# MDEV-12145: IN subquery used in WHERE of EXISTS subquery
#
@@ -2307,8 +2309,8 @@ WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
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 Using where
-2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch
-2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 12.50 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 range i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
@@ -2345,7 +2347,7 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; FirstMatch
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
@@ -2429,11 +2431,10 @@ WHERE t2.ugroup = t3_i.sys_id AND
t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND
t2.user = '86826bf03710200044e0bfc8bcbe5d79');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
-1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where
+1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary
+1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
+1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index
-2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where
-2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
set statement optimizer_prune_level=1 for explain SELECT t1.assignment_group
FROM t1, t3
WHERE t1.assignment_group = t3.sys_id AND
@@ -2444,11 +2445,10 @@ WHERE t2.ugroup = t3_i.sys_id AND
t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND
t2.user = '86826bf03710200044e0bfc8bcbe5d79');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2
-1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where
+1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary
+1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
+1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index
-3 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where
-3 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where
SELECT t1.assignment_group
FROM t1, t3
WHERE t1.assignment_group = t3.sys_id AND
@@ -2491,9 +2491,8 @@ alter table t1 add key(id);
explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
1
@@ -2542,20 +2541,17 @@ drop procedure prepare_data;
set @@optimizer_switch= @local_optimizer_switch;
drop table t1,t2,t3;
CREATE TABLE t1 ( id int NOT NULL, key(id));
-INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19);
+INSERT INTO t1 select seq from seq_11_to_39;
CREATE TABLE t2 (i1 int NOT NULL, i2 int NOT NULL);
-INSERT INTO t2 VALUES (11,11),(12,12),(13,13);
+INSERT INTO t2 select seq,seq+1 from seq_11_to_50;
CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2;
explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t1 index id id 4 NULL 29 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 40 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
1
-1
-1
-1
drop table t1,t2;
drop view v1;
#
diff --git a/mysql-test/main/subselect_sj_mat.test b/mysql-test/main/subselect_sj_mat.test
index 6a9c78adc52..4302fc10c81 100644
--- a/mysql-test/main/subselect_sj_mat.test
+++ b/mysql-test/main/subselect_sj_mat.test
@@ -4,6 +4,7 @@
#
--source include/default_optimizer_switch.inc
+--source include/have_sequence.inc
set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on,semijoin_with_cache=on');
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
@@ -1174,9 +1175,9 @@ set @@optimizer_switch= @local_optimizer_switch;
DROP TABLE t1, t2;
-#
-# BUG#46548 IN-subqueries return 0 rows with materialization=on
-#
+--echo #
+--echo # BUG#46548 IN-subqueries return 0 rows with materialization=on
+--echo #
CREATE TABLE t1 (
pk int,
a varchar(1),
@@ -1186,9 +1187,12 @@ CREATE TABLE t1 (
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
+insert into t1 select seq,'x','xxxx','xxxx','xxxx' from seq_10_to_40;
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
+insert into t2 select -seq,'a','aaaa','aaaa','aaaa' from seq_1_to_20;
+insert into t2 select seq,'b','bbbb','bbbb','bbbb' from seq_100_to_200;
set @local_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch=@optimizer_switch_local_default;
@@ -1553,6 +1557,7 @@ DROP TABLE t1,t2;
--echo #
create table t1 (a int, b int);
insert into t1 values (7,5), (3,3), (5,4), (9,3);
+insert into t1 select seq,seq from seq_100_to_200;
create table t2 (a int, b int, index i_a(a));
@@ -1883,9 +1888,11 @@ drop table t1;
CREATE TABLE t1 (
pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
+create table t2 like t1;
+insert into t2 select * from t1;
SELECT sq1.f2 FROM t1 AS sq1
- WHERE EXISTS ( SELECT * FROM t1 AS sq2
+ WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
set @local_optimizer_switch= @@optimizer_switch;
@@ -1899,12 +1906,12 @@ SELECT sq1.f2 FROM t1 AS sq1
--echo # this checks the result set above
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
- WHERE EXISTS ( SELECT * FROM t1 AS sq2
+ WHERE EXISTS ( SELECT * FROM t2 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
set optimizer_switch= @local_optimizer_switch;
-DROP TABLE t1;
+DROP TABLE t1,t2;
--echo #
--echo # MDEV-12145: IN subquery used in WHERE of EXISTS subquery
@@ -2248,9 +2255,9 @@ set @@optimizer_switch= @local_optimizer_switch;
drop table t1,t2,t3;
CREATE TABLE t1 ( id int NOT NULL, key(id));
-INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19);
+INSERT INTO t1 select seq from seq_11_to_39;
CREATE TABLE t2 (i1 int NOT NULL, i2 int NOT NULL);
-INSERT INTO t2 VALUES (11,11),(12,12),(13,13);
+INSERT INTO t2 select seq,seq+1 from seq_11_to_50;
CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2;
explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
diff --git a/mysql-test/main/subselect_sj_nonmerged.result b/mysql-test/main/subselect_sj_nonmerged.result
index 99ce641da8e..2413ce3a557 100644
--- a/mysql-test/main/subselect_sj_nonmerged.result
+++ b/mysql-test/main/subselect_sj_nonmerged.result
@@ -67,8 +67,8 @@ insert into t4 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t0 A, t0 B;
explain select * from t0, t4 where
t4.b=t0.a and t4.a in (select max(t2.a) from t1, t2 group by t2.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5
+1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t4 eq_ref a a 10 <subquery2>.max(t2.a),test.t0.a 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using temporary
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
diff --git a/mysql-test/main/type_blob.result b/mysql-test/main/type_blob.result
index abde3db7fac..ccbbe5c9118 100644
--- a/mysql-test/main/type_blob.result
+++ b/mysql-test/main/type_blob.result
@@ -625,7 +625,7 @@ id txt
3 NULL
explain select * from t1 where txt='Chevy' or txt is NULL;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL txt_index NULL NULL NULL 6 Using where
+1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where
explain select * from t1 FORCE INDEX (`txt_index`) where txt='Chevy' or txt is NULL;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where
@@ -690,18 +690,18 @@ id txt
2 Chevy
select * from t1 where txt > 'Chevy';
id txt
+7 Ford
4 Honda
-5 Subaru
6 Honda
-7 Ford
+5 Subaru
select * from t1 where txt >= 'Chevy';
id txt
1 Chevy
2 Chevy
+7 Ford
4 Honda
-5 Subaru
6 Honda
-7 Ford
+5 Subaru
alter table t1 modify column txt blob;
explain select * from t1 where txt='Chevy' or txt is NULL;
id select_type table type possible_keys key key_len ref rows Extra
diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result
index c4568e80ae6..96f3c568446 100644
--- a/mysql-test/main/type_datetime.result
+++ b/mysql-test/main/type_datetime.result
@@ -105,7 +105,7 @@ date numfacture expedition
0000-00-00 00:00:00 1212 0001-00-00 00:00:00
EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL expedition NULL NULL NULL 2 Using where
+1 SIMPLE t1 ref expedition expedition 5 const 2
drop table t1;
create table t1 (a datetime not null, b datetime not null);
insert into t1 values (now(), now());
diff --git a/mysql-test/main/view.result b/mysql-test/main/view.result
index aec4a5d09f2..1adf577e4f8 100644
--- a/mysql-test/main/view.result
+++ b/mysql-test/main/view.result
@@ -4213,10 +4213,10 @@ INSERT INTO t2 VALUES
EXPLAIN EXTENDED
SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where
-1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00
+1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 12 75.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`pk` and `test`.`t2`.`pk` > 8
FLUSH STATUS;
SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
a c
@@ -4225,22 +4225,34 @@ a c
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
-Handler_read_key 1
+Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 17
+Handler_read_rnd_next 30
+analyze table t1,t2;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+explain extended SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 16 12.50 Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8
CREATE VIEW v AS SELECT * FROM t2;
EXPLAIN EXTENDED
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where
-1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00
+1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 12 75.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`pk` and `test`.`t2`.`pk` > 8
FLUSH STATUS;
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
a c
@@ -4249,14 +4261,20 @@ a c
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
-Handler_read_key 1
+Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 17
+Handler_read_rnd_next 30
+set statement optimizer_where_cost=100 FOR explain extended SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8
DROP VIEW v;
DROP TABLE t1, t2;
#
diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test
index c1efbbb5000..3b3d1124a09 100644
--- a/mysql-test/main/view.test
+++ b/mysql-test/main/view.test
@@ -4165,12 +4165,18 @@ FLUSH STATUS;
SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
SHOW STATUS LIKE 'Handler_read_%';
+analyze table t1,t2;
+explain extended SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
+
CREATE VIEW v AS SELECT * FROM t2;
EXPLAIN EXTENDED
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
FLUSH STATUS;
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
SHOW STATUS LIKE 'Handler_read_%';
+
+set statement optimizer_where_cost=100 FOR explain extended SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
+
DROP VIEW v;
DROP TABLE t1, t2;